Re: [R] Non-linear Regression best-fit line

2011-06-17 Thread Dennis Murphy
Hi:

Perhaps the self-starting functions may be helpful. See ?selfStart.
There are self-starting functions for both the logistic and Gompertz
models (SSlogis and SSgompertz, respectively). Go through the examples
to see how they work.

HTH,
Dennis

On Fri, Jun 17, 2011 at 2:14 PM, Sean Bignami  wrote:
> I am trying to fit a curve to a cumulative mortality curve (logistic) where y 
> is the cumulative proportion of mortalities, and t is the time in hours (see 
> below). Asym. at 0 and 1
>> y
>  [1] 0. 0.04853859 0.08303777 0.15201970 0.40995074 0.46444992 
> 0.62862069 0.95885057 1.
> [10] 1. 1.
>> t
>  [1]  0 13 20 24 37 42 48 61 72 86 90
>
> I tried to find starting values for a Gompertz non-linear regression by 
> converting the equation (y~1*exp(-beta*exp(-gamma*t)) to a linear form per 
> Dalgaard "Introductory Statistics with R" pg.279-280. But got this Error 
> message:
>
>> lm(log(0-log(y))~t)
> Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
>  NA/NaN/Inf in foreign function call (arg 4)
>
> I tried to change all by 0 and 1 values to non-zero and non-one values (yy 
> and tt below), and was able to get starting estimates.
>
>> yy<-c(0.1,0.04853859, 0.08303777, 0.15201970, 0.40995074, 
>> 0.46444992, 0.62862069, 0.95885057, 
>> 0.99,0.,0.)
>> tt<-c(0.01,13,20,24,37,42,48,61,72,86,90)
>
>> lm(log(0-log(yy))~tt)
>
> Call:
> lm(formula = log(0 - log(yy)) ~ tt)
>
> Coefficients:
> (Intercept)           tt
>     9.5029      -0.3681
>
> However, when I plug those values into the nls function, I get an error 
> message about the "getInitial" method
>
>> nlsout<-nls(y~1*exp(-beta*exp(-gamma*t),start=c(beta=exp(9.5),gamma=.368)));summary(nlsout)
> Error in getInitial.default(func, data, mCall = as.list(match.call(func,  :
>  no 'getInitial' method found for "function" objects
>
> Can anyone help clarify how I can find the parameters for a best-fit curve 
> for this data? Thanks!!
>
> Sean
>        [[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] Bartlett's Test of Sphericity

2011-06-17 Thread Jeremy Miles
cortest.bartlett() in the psych package.

I've never seen a non-significant Bartlett's test.

Jeremy



On 17 June 2011 12:43, thibault grava  wrote:
> Hello Dear R user,
>
> I want to conduct a Principal components analysis and I need to run two
> tests to check whether I can do it or not. I found how to run the KMO
> test, however i cannot find an R fonction for the Bartlett's test of
> sphericity. Does somebody know if it exists?
>
> Thanks for your help!
>
> Thibault
>
>        [[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] double integral calculation

2011-06-17 Thread Moohwan Kim
a=[0.1,0.2,0.1,0.3,0.4]
b=[0.2,0.3,0.1,0.2,0.5]
c=[1,1,1,1,1]
log(c+a-x*b) where x=unknown scale variable.

int=$$log(c+a-x*b)dadb, where $ denotes integral sign.

Actually, how could I calculate the integral's approximation?
double summation?

best,
moohwan

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


Re: [R] graphsheet and export.graph equivalents in R?

2011-06-17 Thread Prof Brian Ripley

On Fri, 17 Jun 2011, Michael Karol wrote:


R Experts



  I'm currently using an S+ script of the following format and would
like to convert it to R. The script opens a graphsheet with an
associated name, plots something (in this case a boxplot) and then
exports the contents of the graphsheet of the assigned name to an EMF
file.  I've been looking for something in R that would work the same way
but to no avail.


Really?: you need to hone your searching skills!  You seem to be using 
Windows without telling us.


See ?windows, which links to ?savePlot.

Note that this is not a recommended way to do things even in S-PLUS 
(sic).  In R, use win.metafile() directly (or preferably a less flaky 
graphics format: just about any other counts as 'less flaky').




   Could someone please show me how this or something similar is done
in R?  (I'm trying to convert to R.)  Thanks.



  graphsheet(Name="SheetOne")

  boxplot(GraphSheet = "SheetOne" , split(Df01$AUC ,
Df01$Response), varwidth=TRUE, whisklty=4, notch = TRUE, ylab ="Y" ,
xlab = "X"  )

  export.graph("C:/SheetOne.EMF", Name = "SheetOne", ExportType =
"EMF" )



Regards,

Michael




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


That does mean you: it asked you not to send HTML but properly 
formatted text email, and to give 'at a minimum' information.


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

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


Re: [R] can this sequence be generated easier?

2011-06-17 Thread Bill.Venables
Here ia an idea that might be useful to adapt

fixedSumCombinations <- function(N, terms) 
if(terms == 1) return(N) else
if(terms == 2) return(cbind(0:N, N:0)) else {
X <- NULL
for(i in 0:N) 
X <- rbind(X, cbind(i, Recall(N-i, terms-1)))
X
}

example:

> fixedSumCombinations(4, 3)
  i
 [1,] 0 0 4
 [2,] 0 1 3
 [3,] 0 2 2
 [4,] 0 3 1
 [5,] 0 4 0
 [6,] 1 0 3
 [7,] 1 1 2
 [8,] 1 2 1
 [9,] 1 3 0
[10,] 2 0 2
[11,] 2 1 1
[12,] 2 2 0
[13,] 3 0 1
[14,] 3 1 0
[15,] 4 0 0

Bill Venables.


From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of 
pdb [ph...@philbrierley.com]
Sent: 18 June 2011 14:34
To: r-help@r-project.org
Subject: [R] can this sequence be generated easier?

I have 'x' variables that I need to find the optimum combination of, with the
constraint that the sum of all x variables needs to be exactly 100. I need
to test all combinations to get the optimal mix.

This is easy if I know how many variables I have - I can hard code as below.
But what if I don't know the number of variables and want this to be a
flexible parameter. Is there a sexy recursive way that this can be done in
R?

#for combinations of 2 variables
vars = 2
for(i in 0:100){
for(j in 0:(100-i)){
...do some test i,j combination
}}

#for combinations of 3 variables
vars = 3
for(i in 0:100){
for(j in 0:(100-i)){
for(k in 0:100-(i+j)){
...do some test on i,j,k combination
}}}



--
View this message in context: 
http://r.789695.n4.nabble.com/can-this-sequence-be-generated-easier-tp3607240p3607240.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] How to join matrices of different row length from a list

2011-06-17 Thread Jeff Newmiller
No.
---
Jeff Newmiller The . . Go Live...
DCN: Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Sheng Lin  wrote:

Can this be used in matplot(x,y,)? where x and y have matching rows.
However, each column may have different rows or length. Thanks. Sheng

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-join-matrices-of-different-row-length-from-a-list-tp3177212p3607158.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.


[[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] can this sequence be generated easier?

2011-06-17 Thread pdb
I have 'x' variables that I need to find the optimum combination of, with the
constraint that the sum of all x variables needs to be exactly 100. I need
to test all combinations to get the optimal mix.

This is easy if I know how many variables I have - I can hard code as below.
But what if I don't know the number of variables and want this to be a
flexible parameter. Is there a sexy recursive way that this can be done in
R?

#for combinations of 2 variables
vars = 2
for(i in 0:100){
for(j in 0:(100-i)){
...do some test i,j combination
}}

#for combinations of 3 variables
vars = 3
for(i in 0:100){
for(j in 0:(100-i)){
for(k in 0:100-(i+j)){
...do some test on i,j,k combination
}}}



--
View this message in context: 
http://r.789695.n4.nabble.com/can-this-sequence-be-generated-easier-tp3607240p3607240.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] Bartlett's Test of Sphericity

2011-06-17 Thread Daniel Malter
The formula for the chi-square value is:

-( (n-1) - (2*p-5)/6 )* log(det(R))

where n is the number of observations, p is the number of variables, and R
is the correlation matrix. The chi square test is then performed on
(p^2-p)/2 degrees of freedom. So you can compute it by hand. Or you can use
the function below (no warranty) where you supply the data as data frame to
the function bartlett.sphere()

example:

x<-rnorm(100)
y<-x+rnorm(100,0,0.1)

bartlett.sphere<-function(data){chi.square=-( (dim(data)[1]-1) -
(2*dim(data)[2]-5)/6 )*
log(det(cor(data,use='pairwise.complete.obs')));cat('chi.square value ',
chi.square , ' on ', (dim(data)[2]^2-dim(data)[2])/2, ' degrees of freedom.'
, ' p-value: ', 1-pchisq(chi.square,(dim(data)[2]^2-dim(data)[2])/2))}

bartlett.sphere(data.frame(x,y))

HTH,
Daniel




thibault grava-3 wrote:
> 
> Hello Dear R user,
> 
> I want to conduct a Principal components analysis and I need to run two 
> tests to check whether I can do it or not. I found how to run the KMO 
> test, however i cannot find an R fonction for the Bartlett's test of 
> sphericity. Does somebody know if it exists?
> 
> Thanks for your help!
> 
> Thibault
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

--
View this message in context: 
http://r.789695.n4.nabble.com/Bartlett-s-Test-of-Sphericity-tp3606765p3607184.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How to join matrices of different row length from a list

2011-06-17 Thread Sheng Lin
Can this be used in matplot(x,y,)? where x and y have matching rows.
However, each column may have different rows or length. Thanks. Sheng

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-join-matrices-of-different-row-length-from-a-list-tp3177212p3607158.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] Conditional Correlation

2011-06-17 Thread Daniel Malter
This question was just answered yesterday in this post:
http://r.789695.n4.nabble.com/Correlations-by-subgroups-td3599548.html#a3600553

One solution:

x<-c(1,1,1,1,1,2,2,2,2,2) 
y<-rnorm(10) 
z<-y+rnorm(10) 
by(data.frame(y,z),factor(x),cor) 

HTH,
Daniel



Mateus Rabello wrote:
> 
> Hi, 
> How can I accomplish this in R. Example:  
> 
> I have the following data.frame:
> 
> data <-
> data.frame(x=c(1,2,3,4,5,6,5,3,7,1,0,4,8),y=c(1,2,1,2,2,2,1,1,1,2,2,2,2),z=c(5,8,4,3,4,1,6,3,3,6,3,5,7))
> 
> Supposing that data$y is a factor, I would like to find the Spearman
> correlation between data$x and data$z indexing it by data$y. 
> To be more specific, I want to find two correlations: between x and z with
> y==1 and the same correlation with x and z where y==2.
> Something like:
> 
> cor(data$x[data$y==1],data$z[data$y==1],method= "spearman") and
> cor(data$x[data$y==2],data$z[data$y==2],method= "spearman"),
> 
> but without having to write all the values for data$y and use cor more
> than once.
> 
> I hope I made myself clear.
> Thanks
> Mateus
> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

--
View this message in context: 
http://r.789695.n4.nabble.com/Conditional-Correlation-tp3607080p3607134.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] Conditional Correlation

2011-06-17 Thread Mateus Rabello
Hi, 
How can I accomplish this in R. Example:  

I have the following data.frame:

data <- 
data.frame(x=c(1,2,3,4,5,6,5,3,7,1,0,4,8),y=c(1,2,1,2,2,2,1,1,1,2,2,2,2),z=c(5,8,4,3,4,1,6,3,3,6,3,5,7))

Supposing that data$y is a factor, I would like to find the Spearman 
correlation between data$x and data$z indexing it by data$y. 
To be more specific, I want to find two correlations: between x and z with y==1 
and the same correlation with x and z where y==2.
Something like:

cor(data$x[data$y==1],data$z[data$y==1],method= "spearman") and 
cor(data$x[data$y==2],data$z[data$y==2],method= "spearman"),

but without having to write all the values for data$y and use cor more than 
once.

I hope I made myself clear.
Thanks
Mateus


[[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] Vim-R-Plugin issue : Python interface must be enabled to run Vim-R-Plugin

2011-06-17 Thread Idris Raja
I am trying to get the
Vim-R-Plugin to
work with gvim and R on Windows 7.

When I open a .R file in VIM, it complains and says ""Python interface must
be enabled to run Vim-R-Plugin."  I have installed pywin32 for python 2.7,
and added the following 4 lines to my _vimrc per the instructions
here
.

set nocompatible
syntax enable
filetype plugin on
filetype indent on

Ideas on how to fix this?

On Fri, Jun 17, 2011 at 2:41 AM, Yoni Teitelbaum <
yoni.teitelb...@escapemg.com> wrote:
> Hello all,
>
>
> I have a php script that makes a call
>
>
> system(PATH_PROJECT_ROOT . '/sh/combineDays.sh ' . $dateString . " " .
PATH_PROJECT_ROOT);
>
>
> and within combineDays.sh I run an R script:
>
>
> R --slave --vanilla --args $testDates $BASEDIR $defaultSearchVersion <
$BASEDIR"R/combineDays.R"
>
>
> At the end of this R script, I try to write results to a file, but the
script seems to stop executing after I call sink(results.file) in the R
script. I previously observed similar behavior when trying to call library()
from within the same R script.
>
>
> When I run combineDays.sh from the shell, everything works fine.
>
>
> Any ideas?
>
>
> Thanks.
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[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] sink() and library() calls cause script to stop when called from php

2011-06-17 Thread Yoni Teitelbaum
chmod 777 on the destination folder fixed the sink() issue. Still don't know 
why library() was causing the script to stop though. 

- Original Message -

From: "Yoni Teitelbaum"  
To: r-help@r-project.org 
Sent: Friday, June 17, 2011 5:41:33 AM 
Subject: [R] sink() and library() calls cause script to stop when called from 
php 

Hello all, 


I have a php script that makes a call 


system(PATH_PROJECT_ROOT . '/sh/combineDays.sh ' . $dateString . " " . 
PATH_PROJECT_ROOT); 


and within combineDays.sh I run an R script: 


R --slave --vanilla --args $testDates $BASEDIR $defaultSearchVersion < 
$BASEDIR"R/combineDays.R" 


At the end of this R script, I try to write results to a file, but the script 
seems to stop executing after I call sink(results.file) in the R script. I 
previously observed similar behavior when trying to call library() from within 
the same R script. 


When I run combineDays.sh from the shell, everything works fine. 


Any ideas? 


Thanks. 
[[alternative HTML version deleted]] 

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


[[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] rle on large data . . . without a for loop!

2011-06-17 Thread Justin
Justin  gmail.com> writes:

> > I think need to do something like this:
> > 
> > dat<-data.frame(state=sample(id=rep(1:5,each=200),1:3, 1000,
> > replace=T,prob=c(0.7,0.05,0.25)),V1=runif(1,10,1000),V2=rnorm(1000))
> 
> brown bag...

... its friday and im sleepy!...

dat<-data.frame(id=rep(1:5,each=200),state=sample(1:3,
1000,replace=T,prob=c(0.7,0.05,0.25)),V1=runif(1,10,1000),V2=rnorm(1000))

> snipped
> 
> > Thanks,
> > 
> > Justin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Inconsistent results from var.get.nc in RNetCDF

2011-06-17 Thread C. Susannah Tysor
Hello -

I am having trouble extracting data from NetCDF data files using
RNetCDF. The data files each have 3 dimensions (longitude, latitude,
and a date) and 3 variables (latitude, longitude, and a climate
variable).

Here is some of the output from print.nc for clarity:

-
dimensions:
  month = UNLIMITED ; // (1368 currently)
  lat = 3105 ;
  lon = 7025 ;
variables:
  float lat(lat) ;
  lat:long_name = "latitude" ;
  lat:standard_name = "latitude" ;
  lat:units = "degrees_north" ;
  float lon(lon) ;
  lon:long_name = "longitude" ;
  lon:standard_name = "longitude" ;
  lon:units = "degrees_east" ;
  short tmax(lon, lat, month) ;
  tmax:missing_value = - ;
  tmax:_FillValue = - ;
  tmax:units = "degree_celsius" ;
  tmax:scale_factor = 0.01 ;
  tmax:valid_min = -5000 ;
  tmax:valid_max = 6000 ;
-

I am getting behavior I don't understand when I use the var.get.nc
function from the RNetCDF package.

For example, when I attempt to extract 82 values beginning at stval
from the maximum temperature data with
   > var.get.nc(p8m.tmax,'tmax', start=c(lon_val, lat_val, stval),
count=c(1,1,82))
I get
   Error: Invalid argument


But after successfully running
   > var.get.nc(p8m.tmax,'tmax', start=c(lon_val, lat_val, stval),
count=c(1,1,80))
   > var.get.nc(p8m.tmax,'tmax', start=c(lon_val, lat_val, stval),
count=c(1,1,81))
the command with 82 works:
   > var.get.nc(p8m.tmax,'tmax', start=c(lon_val, lat_val, stval),
count=c(1,1,82))
[1]  444  866 1063 1496 1905 2625 2662 2515 2016 1282  862  270
850  560 1002 1069 1900 2394 2721 2352 2192 1843  656  483  350  384
1532 1219 1929 2428
   [31] 2517 2288 2038 1209  527  489  407  505  899 1252 1885 2193
2707 2220 2040 1498 1040  689  594  941  729 1374 2016 2556 2475 2193
1841 1316 1010  476
   [61]  202  646 1266 1357 1860 2451 2530 2355 2010 1519 1210  228
173  600 1037 1316 1530 2389 2358 2303 2052 1583

The same occurs in the identically structured tmin file, but at 36
instead of 82:
  > var.get.nc(p8m.tmin,'tmin', start=c(lon_val, lat_val, stval),
count=c(1,1,36))
produces
   Error: Invalid argument

But after repeating the command with 30, 31, etc
   >var.get.nc(p8m.tmin,'tmin', start=c(lon_val, lat_val, stval),
count=c(1,1,36)) works.

Does anyone know what causes the initial failure to extract the
variable? And how I might prevent it?

Thanks!
Susannah

---
C. Susannah Tysor
Research Assistant
Pinyon Ecology Research Group
Northern Arizona University

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


[R] Using MCMC sampling to estimate p values with a mixed model

2011-06-17 Thread ps0u5145
Hi everyone,

Apologies if this is a silly question but I am a student and this is my
first time using R so I am still trying to educate myself on commands,
models e.t.c

I have a mixed model with four dichotomous fixed factors and subject as a
random factor (as each person completed four vignettes, with factors crossed
across vignettes).

I have run an lmer model and used the Monte Carlo method to see if there are
any significant main effects or interactions. However, when I looked at the
p values some are showing as significant although the F value is less than
1. Is it possible to have a significant effect with an F value below 1?. 

I have a sample size of 150 and have read that the pMCMC values can be
anti-conservative so wonder if it is because my sample size may be too
small?.

Thank you for any help

--
View this message in context: 
http://r.789695.n4.nabble.com/Using-MCMC-sampling-to-estimate-p-values-with-a-mixed-model-tp3606654p3606654.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] graphsheet and export.graph equivalents in R?

2011-06-17 Thread Michael Karol
R Experts

 

   I'm currently using an S+ script of the following format and would
like to convert it to R. The script opens a graphsheet with an
associated name, plots something (in this case a boxplot) and then
exports the contents of the graphsheet of the assigned name to an EMF
file.  I've been looking for something in R that would work the same way
but to no avail.

Could someone please show me how this or something similar is done
in R?  (I'm trying to convert to R.)  Thanks.

 

   graphsheet(Name="SheetOne") 

   boxplot(GraphSheet = "SheetOne" , split(Df01$AUC ,
Df01$Response), varwidth=TRUE, whisklty=4, notch = TRUE, ylab ="Y" ,
xlab = "X"  )

   export.graph("C:/SheetOne.EMF", Name = "SheetOne", ExportType =
"EMF" )

 

Regards, 

Michael

 


[[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] Non-linear Regression best-fit line

2011-06-17 Thread Sean Bignami
I am trying to fit a curve to a cumulative mortality curve (logistic) where y 
is the cumulative proportion of mortalities, and t is the time in hours (see 
below). Asym. at 0 and 1
> y
 [1] 0. 0.04853859 0.08303777 0.15201970 0.40995074 0.46444992 
0.62862069 0.95885057 1.
[10] 1. 1.
> t
 [1]  0 13 20 24 37 42 48 61 72 86 90

I tried to find starting values for a Gompertz non-linear regression by 
converting the equation (y~1*exp(-beta*exp(-gamma*t)) to a linear form per 
Dalgaard "Introductory Statistics with R" pg.279-280. But got this Error 
message:

> lm(log(0-log(y))~t)
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
  NA/NaN/Inf in foreign function call (arg 4)

I tried to change all by 0 and 1 values to non-zero and non-one values (yy and 
tt below), and was able to get starting estimates.

> yy<-c(0.1,0.04853859, 0.08303777, 0.15201970, 0.40995074, 0.46444992, 
> 0.62862069, 0.95885057, 0.99,0.,0.)
> tt<-c(0.01,13,20,24,37,42,48,61,72,86,90)

> lm(log(0-log(yy))~tt)

Call:
lm(formula = log(0 - log(yy)) ~ tt)

Coefficients:
(Intercept)   tt  
 9.5029  -0.3681 

However, when I plug those values into the nls function, I get an error message 
about the "getInitial" method

> nlsout<-nls(y~1*exp(-beta*exp(-gamma*t),start=c(beta=exp(9.5),gamma=.368)));summary(nlsout)
Error in getInitial.default(func, data, mCall = as.list(match.call(func,  : 
  no 'getInitial' method found for "function" objects

Can anyone help clarify how I can find the parameters for a best-fit curve for 
this data? Thanks!!

Sean
[[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] Size argument in sample function

2011-06-17 Thread Weidong Gu
you can do something like this

x<-rnorm(20,0,1)
time=c(1,2,3)
sapply(1:length(time),function(t) sample(x,time[t]))

Weidong Gu

On Fri, Jun 17, 2011 at 9:59 AM, alfredo  wrote:
> Hi All,
>
> I'd like to randomly sample a vector N times, where each successive random
> sample increases in size. I have realised that the function sample does not
> take vectors for arguments. For example,
>
> x<-rnorm(20,0,1)
> sample(x,c(1,2,3)) ## will only return one random sample of size 1.
>
> The trick seems to be getting past the size argument of the function. I've
> tried different things without success. Any help would be most appreciated!
>
> Thanks,
>
> A
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Size-argument-in-sample-function-tp3605486p3605486.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] Bartlett's Test of Sphericity

2011-06-17 Thread thibault grava
Hello Dear R user,

I want to conduct a Principal components analysis and I need to run two 
tests to check whether I can do it or not. I found how to run the KMO 
test, however i cannot find an R fonction for the Bartlett's test of 
sphericity. Does somebody know if it exists?

Thanks for your help!

Thibault

[[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] rle on large data . . . without a for loop!

2011-06-17 Thread Justin
Justin Haynes  gmail.com> writes:

> 
> I think need to do something like this:
> 
> dat<-data.frame(state=sample(id=rep(1:5,each=200),1:3, 1000,
> replace=T,prob=c(0.7,0.05,0.25)),V1=runif(1,10,1000),V2=rnorm(1000))

brown bag...

dat<-data.frame(id=rep(1:5,each=200),state=sample(1:3, 1000,
replace=T),prob=c(0.7,0.05,0.25)),V1=runif(1,10,1000),V2=rnorm(1000))


> rle.dat<-rle(dat$state)
> temp<-1
> out<-data.frame(id=1:length(rle.dat$length))

snipped

> Thanks,
> 
> Justin
> 
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] rle on large data . . . without a for loop!

2011-06-17 Thread Justin Haynes
I think need to do something like this:

dat<-data.frame(state=sample(id=rep(1:5,each=200),1:3, 1000,
replace=T,prob=c(0.7,0.05,0.25)),V1=runif(1,10,1000),V2=rnorm(1000))
rle.dat<-rle(dat$state)
temp<-1
out<-data.frame(id=1:length(rle.dat$length))
for(i in 1:length(rle.dat$length)){
temp2<-temp+rle.dat$length[[i]]
out$V1[i]<-mean(dat$V1[temp:temp2])
out$V2[i]<-sum(dat$V2[temp:temp2])
out$state[i]<-rle.dat$value[[i]]
temp<-temp2
}

to a very large dataset.  I want to apply a few summary functions to
some variables within a data.frame for given states. to complicate
things, id like to use plyr and split on the id variable before i do
any of this...

loop.func<-function(dat){
  rle.dat<-rle(dat$state)
  temp<-1
  out<-data.frame(id=1:length(rle.dat$length))
  for(i in 1:length(rle.dat$length)){
temp2<-temp+rle.dat$length[[i]]
out$V1[i]<-mean(dat$V1[temp:temp2])
out$V2[i]<-sum(dat$V2[temp:temp2])
out$state[i]<-rle.dat$value[[i]]
temp<-temp2
  }
  return(out)
}
out<-ddply(dat,.(id),loop.func)

mostly, i just don't understand how to use a list (especially in this
instance) in a plyr/apply statement...


Thanks,

Justin

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


Re: [R] Size argument in sample function

2011-06-17 Thread Joshua Wiley
Hi,

There is nothing sacrosanct about taking a random sample of size 1 then 2 then 
3 versus just taking one random sample of size 6 (with replacement, if you 
like) and then just use the first element, elements 2:3 and elements 4:6.

HTH,

Josh

On Jun 17, 2011, at 6:59, alfredo  wrote:

> Hi All,
> 
> I'd like to randomly sample a vector N times, where each successive random
> sample increases in size. I have realised that the function sample does not
> take vectors for arguments. For example,
> 
> x<-rnorm(20,0,1)
> sample(x,c(1,2,3)) ## will only return one random sample of size 1. 
> 
Dat <- sample(x, 6)

Dat[1]
Dat[2:3]
Dat[4:6]

> The trick seems to be getting past the size argument of the function. I've
> tried different things without success. Any help would be most appreciated!
> 
> Thanks,
> 
> A
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Size-argument-in-sample-function-tp3605486p3605486.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] is this a bug?

2011-06-17 Thread Brian Diggs

On 6/17/2011 2:24 PM, (Ted Harding) wrote:

And the extra twist in the tale is exemplified by this
mini-version of Albert-Jan's first example:

   DF<- data.frame(A=c(1,2,3))
   DF$B<- c(4,5,6)
   DF$C<- c(7,8,9)
   DF
   #   A B C
   # 1 1 4 7
   # 2 2 5 8
   # 3 3 6 9

   DF$D<- DF["A"]/DF["B"]
   DF
   #   A B CA
   # 1 1 4 7 0.25
   # 2 2 5 8 0.40
   # 3 3 6 9 0.50

##And why:

   DF["A"]/DF["B"]
   #  A
   # 1 0.25
   # 2 0.40
   # 3 0.50

##So the ratio DF["A"]/DF["B"] comes out with the name of
##the numerator, "A". This is then the name given to DF$D


It's even slightly weirder than that:

str(DF)
#'data.frame':   3 obs. of  4 variables:
# $ A: num  1 2 3
# $ B: num  4 5 6
# $ C: num  7 8 9
# $ D:'data.frame':  3 obs. of  1 variable:
#  ..$ A: num  0.25 0.4 0.5

There is a column D in DF which is itself a data frame with a single 
column whose name is A (because of what Ted said).  When formatted for 
printing out, the column name of the inner data frame is used (as a 
result of how data.frame() itself handles named arguments when the 
argument is itself a data.frame: "If a list or data frame or matrix is 
passed to data.frame it is as if each component or column had been 
passed as a separate argument...").


So not a bug, but a convoluted set of circumstances that can happen when 
non-atomic vectors are assigned to columns of a data.frame.  That's one 
of those /you shouldn't do that even though it is technically legal or 
at least you shouldn't be surprised when things don't work the way you 
thought they would/ things.



Thus Albert-Jan's
   df["weight"] / ave(df["weight"], df["sex"], FUN=sum)*100
comes through with name "weight".

Ted.


On 17-Jun-11 21:06:42, William Dunlap wrote:

df$varname is a column of df.

df["varname"] is a one-column df containing that column.

df[["varname"]] is a column of df (same as df$varname).

df[,"varname"] is a column of df (same as df$varname).

df[,"varname",drop=FALSE] is a one-column df (same as df$varname).

df$newVarname<- df["varname"] inserts a new component
into df, the component being a one-column data.frame,
not the column in that data.frame.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of Albert-Jan Roskam
Sent: Friday, June 17, 2011 1:49 PM
To: R Mailing List
Subject: [R] is this a bug?

Hello,

Is the following a bug? I always thought that df$varname<-
does the same as
df["varname"]<-


df<- data.frame(weight=round(runif(10, 10, 100)),

sex=round(runif(100, 0,
1)))

df$pct<- df["weight"] / ave(df["weight"], df["sex"], FUN=sum)*100
names(df)

[1] "weight" "sex""pct" ### -->  ok

head(df)

   weight sexweight  ### -->  huh!?!
1 86   0 2.4002233
2 19   1 0.5643006
3 32   0 0.8931063
4 87   0 2.4281328
5 45   0 1.2559308
6 95   0 2.6514094

rm(df)
df<- data.frame(weight=round(runif(10, 10, 100)),

sex=round(runif(100, 0,
1)))

df["pct"]<- df["weight"] / ave(df["weight"], df["sex"],

FUN=sum)*100 ###

->  this does work
names(df)

[1] "weight" "sex""pct"

head(df)

   weight sex   pct
1 15   0 0.5246590
2 43   0 1.5040224
3 17   1 0.9284544
4 44   1 2.4030584
5 76   1 4.1507373
6 59   0 2.0636586

do.call(c, R.Version())

platformarch
 "i686-pc-linux-gnu"  "i686"
  os  system
 "linux-gnu"   "i686, linux-gnu"
  status   major
  "" "2"
   minoryear
  "11.1"  "2010"
   month day
"05""31"
 svn revlanguage
 "52157" "R"
  version.string
"R version 2.11.1 (2010-05-31)"

# Thanks!


Cheers!!
Albert-Jan


~~
All right, but apart from the sanitation, the medicine,
education, wine, public
order, irrigation, roads, a fresh water system, and public
health, what have the
Romans ever done for us?
~~

  [[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/li

Re: [R] is this a bug?

2011-06-17 Thread Ted Harding
And the extra twist in the tale is exemplified by this
mini-version of Albert-Jan's first example:

  DF <- data.frame(A=c(1,2,3))
  DF$B <- c(4,5,6)
  DF$C <- c(7,8,9)
  DF
  #   A B C
  # 1 1 4 7
  # 2 2 5 8
  # 3 3 6 9

  DF$D <- DF["A"]/DF["B"]
  DF
  #   A B CA
  # 1 1 4 7 0.25
  # 2 2 5 8 0.40
  # 3 3 6 9 0.50

##And why:

  DF["A"]/DF["B"]
  #  A
  # 1 0.25
  # 2 0.40
  # 3 0.50

##So the ratio DF["A"]/DF["B"] comes out with the name of
##the numerator, "A". This is then the name given to DF$D

Thus Albert-Jan's
  df["weight"] / ave(df["weight"], df["sex"], FUN=sum)*100
comes through with name "weight".

Ted.


On 17-Jun-11 21:06:42, William Dunlap wrote:
> df$varname is a column of df.
> 
> df["varname"] is a one-column df containing that column.
> 
> df[["varname"]] is a column of df (same as df$varname).
> 
> df[,"varname"] is a column of df (same as df$varname).
> 
> df[,"varname",drop=FALSE] is a one-column df (same as df$varname).
> 
> df$newVarname <- df["varname"] inserts a new component
> into df, the component being a one-column data.frame,
> not the column in that data.frame.
> 
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com  
> 
>> -Original Message-
>> From: r-help-boun...@r-project.org 
>> [mailto:r-help-boun...@r-project.org] On Behalf Of Albert-Jan Roskam
>> Sent: Friday, June 17, 2011 1:49 PM
>> To: R Mailing List
>> Subject: [R] is this a bug?
>> 
>> Hello,
>> 
>> Is the following a bug? I always thought that df$varname <- 
>> does the same as 
>> df["varname"] <-
>> 
>> > df <- data.frame(weight=round(runif(10, 10, 100)), 
>> sex=round(runif(100, 0, 
>> 1)))
>> > df$pct <- df["weight"] / ave(df["weight"], df["sex"], FUN=sum)*100
>> > names(df)
>> [1] "weight" "sex""pct" ### --> ok
>> > head(df)
>>   weight sexweight  ### --> huh!?!
>> 1 86   0 2.4002233
>> 2 19   1 0.5643006
>> 3 32   0 0.8931063
>> 4 87   0 2.4281328
>> 5 45   0 1.2559308
>> 6 95   0 2.6514094
>> > rm(df)
>> > df <- data.frame(weight=round(runif(10, 10, 100)), 
>> sex=round(runif(100, 0, 
>> 1)))
>> > df["pct"] <- df["weight"] / ave(df["weight"], df["sex"], 
>> FUN=sum)*100 ### 
>> >-> this does work
>> > names(df)
>> [1] "weight" "sex""pct"   
>> > head(df)
>>   weight sex   pct
>> 1 15   0 0.5246590
>> 2 43   0 1.5040224
>> 3 17   1 0.9284544
>> 4 44   1 2.4030584
>> 5 76   1 4.1507373
>> 6 59   0 2.0636586
>> > do.call(c, R.Version())
>>platformarch 
>> "i686-pc-linux-gnu"  "i686" 
>>  os  system 
>> "linux-gnu"   "i686, linux-gnu" 
>>  status   major 
>>  "" "2" 
>>   minoryear 
>>  "11.1"  "2010" 
>>   month day 
>>"05""31" 
>> svn revlanguage 
>> "52157" "R" 
>>  version.string 
>> "R version 2.11.1 (2010-05-31)" 
>> > # Thanks!
>> 
>> Cheers!!
>> Albert-Jan
>> 
>> 
>> ~~
>> All right, but apart from the sanitation, the medicine, 
>> education, wine, public 
>> order, irrigation, roads, a fresh water system, and public 
>> health, what have the 
>> Romans ever done for us?
>> ~~
>> 
>>  [[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.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 17-Jun-11   Time: 22:24:41
-- XFMail --

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


Re: [R] is this a bug?

2011-06-17 Thread William Dunlap
df$varname is a column of df.

df["varname"] is a one-column df containing that column.

df[["varname"]] is a column of df (same as df$varname).

df[,"varname"] is a column of df (same as df$varname).

df[,"varname",drop=FALSE] is a one-column df (same as df$varname).

df$newVarname <- df["varname"] inserts a new component
into df, the component being a one-column data.frame,
not the column in that data.frame.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Albert-Jan Roskam
> Sent: Friday, June 17, 2011 1:49 PM
> To: R Mailing List
> Subject: [R] is this a bug?
> 
> Hello,
> 
> Is the following a bug? I always thought that df$varname <- 
> does the same as 
> df["varname"] <-
> 
> > df <- data.frame(weight=round(runif(10, 10, 100)), 
> sex=round(runif(100, 0, 
> 1)))
> > df$pct <- df["weight"] / ave(df["weight"], df["sex"], FUN=sum)*100
> > names(df)
> [1] "weight" "sex""pct" ### --> ok
> > head(df)
>   weight sexweight  ### --> huh!?!
> 1 86   0 2.4002233
> 2 19   1 0.5643006
> 3 32   0 0.8931063
> 4 87   0 2.4281328
> 5 45   0 1.2559308
> 6 95   0 2.6514094
> > rm(df)
> > df <- data.frame(weight=round(runif(10, 10, 100)), 
> sex=round(runif(100, 0, 
> 1)))
> > df["pct"] <- df["weight"] / ave(df["weight"], df["sex"], 
> FUN=sum)*100 ### 
> >-> this does work
> > names(df)
> [1] "weight" "sex""pct"   
> > head(df)
>   weight sex   pct
> 1 15   0 0.5246590
> 2 43   0 1.5040224
> 3 17   1 0.9284544
> 4 44   1 2.4030584
> 5 76   1 4.1507373
> 6 59   0 2.0636586
> > do.call(c, R.Version())
>platformarch 
> "i686-pc-linux-gnu"  "i686" 
>  os  system 
> "linux-gnu"   "i686, linux-gnu" 
>  status   major 
>  "" "2" 
>   minoryear 
>  "11.1"  "2010" 
>   month day 
>"05""31" 
> svn revlanguage 
> "52157" "R" 
>  version.string 
> "R version 2.11.1 (2010-05-31)" 
> > # Thanks!
> 
> Cheers!!
> Albert-Jan
> 
> 
> ~~
> All right, but apart from the sanitation, the medicine, 
> education, wine, public 
> order, irrigation, roads, a fresh water system, and public 
> health, what have the 
> Romans ever done for us?
> ~~
> 
>   [[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] combining strings

2011-06-17 Thread Greg Snow
What do you want to happen when both are NA? what do you want to happen if both 
have values?

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Erin Hodgess
> Sent: Thursday, June 16, 2011 7:59 PM
> To: R help
> Subject: [R] combining strings
> 
> Dear R People:
> 
> Suppose I have the following two character vectors:
> 
>  xf
>  [1] "W" NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
> > xg
>  [1] NA  "k" "h" NA  "g" "r" "j" NA  "v" "d" NA  "v" NA  "z" "r" "r"
> "i"
> >
> 
> I want to end up with
> 
> "W" "k" "h" ...
> 
> What is the best way to achieve this, please?  I was thinking that if
> there is an exclusive "or" that it might work.  I've tried all kinds
> of ifs, and ifelse, to no avail.
> 
> 
> 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.

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

2011-06-17 Thread Albert-Jan Roskam
Hello,

Is the following a bug? I always thought that df$varname <- does the same as 
df["varname"] <-

> df <- data.frame(weight=round(runif(10, 10, 100)), sex=round(runif(100, 0, 
1)))
> df$pct <- df["weight"] / ave(df["weight"], df["sex"], FUN=sum)*100
> names(df)
[1] "weight" "sex""pct" ### --> ok
> head(df)
  weight sexweight  ### --> huh!?!
1 86   0 2.4002233
2 19   1 0.5643006
3 32   0 0.8931063
4 87   0 2.4281328
5 45   0 1.2559308
6 95   0 2.6514094
> rm(df)
> df <- data.frame(weight=round(runif(10, 10, 100)), sex=round(runif(100, 0, 
1)))
> df["pct"] <- df["weight"] / ave(df["weight"], df["sex"], FUN=sum)*100 ### 
>-> this does work
> names(df)
[1] "weight" "sex""pct"   
> head(df)
  weight sex   pct
1 15   0 0.5246590
2 43   0 1.5040224
3 17   1 0.9284544
4 44   1 2.4030584
5 76   1 4.1507373
6 59   0 2.0636586
> do.call(c, R.Version())
   platformarch 
"i686-pc-linux-gnu"  "i686" 
 os  system 
"linux-gnu"   "i686, linux-gnu" 
 status   major 
 "" "2" 
  minoryear 
 "11.1"  "2010" 
  month day 
   "05""31" 
svn revlanguage 
"52157" "R" 
 version.string 
"R version 2.11.1 (2010-05-31)" 
> # Thanks!

Cheers!!
Albert-Jan


~~
All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a fresh water system, and public health, what have 
the 
Romans ever done for us?
~~

[[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] Polygon question

2011-06-17 Thread Greg Snow
Does this do what you want?

x <- abs(rnorm(100))
tt <- 1:100
m <- mean(x)
par(mfrow=c(2,1))
yy <- c(0,3)# y-limit
plot(tt,x,type="l",ylim=yy)
abline(h=m)
clip(0,100,0,m)
polygon( c(1,tt,100), c(m,x,m), col='red' )


-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Muhammad Rahiz
> Sent: Thursday, June 16, 2011 3:35 PM
> To: x.r-help
> Subject: [R] Polygon question
> 
> Hi all,
> 
> I have the following script which fills the values which are less than
> the mean of a given timeseries.
> 
> If you look closely, the colored regions are "out of line".
> 
> Any suggestions how I can rectify this?
> 
> Thanks
> 
> Muhammad
> 
> 
> # -
> #rm(list=ls())
> 
> x <- abs(rnorm(100))
> tt <- 1:100
> 
> m <- mean(x)
> w  <- which(x>=m)
> 
> x1 <- x ; x2 <- x ; x3 <- x
> x1[w] <- m
> x2[1:length(x)] <- m
> 
> tx <- c(tt,rev(tt)) ; ty <- c(x1,rev(x2))
> 
> par(mfrow=c(2,1))
> yy <- c(0,3)  # y-limit
> 
> plot(tt,x,type="l",ylim=yy)
> abline(h=m)
> 
> plot(tx,ty,type="n",ylim=yy)
> polygon(tx,ty,col="red")
> lines(x)
> # -
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] prediction intervals

2011-06-17 Thread Greg Snow
I am not an expert in time series (that is why I referred you to the task view 
rather than give my own inexpert opinion).  I do remember from a textbook that 
covered the basics of time series that prediction 2 time points ahead was 
different from plugging in the next time estimate and predicting one ahead.  
And basic theory of linear models also supports this.

The standard linear model assumes all x's to be fixed (or independent of each 
other if random) if you add a new x that is not independent and not fixed, then 
this does not hold.  There is also a whole area of linear models for what to do 
if x is not an exact value but measured with error (or predicted), another area 
that I know exists and is complicated, but which I have not studied beyond the 
basics.

Also the standard formula for prediction intervals has a piece to account for 
variability around the mean and another piece to account for the variability in 
the estimate of the mean due to the coefficients being estimates rather than 
known quantities, it only makes sense that there should be another piece to 
account for uncertainty due to the value of x in the prediction when it is not 
known.

The best I can recommend is look through the task view.  Maybe someone else has 
a better refrence.

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111

From: Dave Evens [mailto:daveeve...@yahoo.co.uk]
Sent: Friday, June 17, 2011 1:48 AM
To: Greg Snow; r-help@r-project.org
Subject: Re: [R] prediction intervals

Thank you for your post Greg.
Do you have any useful references regarding this variability (papers etc)?

Many thanks.
Dave


From: Greg Snow 
To: Dave Evens ; "r-help@r-project.org" 

Sent: Thursday, 16 June 2011, 21:32
Subject: RE: [R] prediction intervals

I don't think that this approach is appropriate here.  Each iteration after the 
1st the lm/predict combination will assume that the new data is exact when in 
fact it is an estimate with some error involved.  To properly do this you need 
to take into account that variability.  There is a time series task view on 
CRAN that may point you to better tools.

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-bounces@r-
> project.org] On Behalf Of Dave Evens
> Sent: Thursday, June 16, 2011 11:33 AM
> To: r-help@r-project.org
> Subject: [R] prediction intervals
>
>
>
> Dear members,
>
> I'm fitting linear model using "lm" which has numerous auto-regressive
> terms as well as other explanatory variables. In order to calculate
> prediction intervals, i've used a for-loop as the auto-regressive
> parameters need to be updated each time so that a new forecast and
> corresponding prediction interval can be calculated.
>
> I'm fitting a number of these models which have different values for
> the response variable and possibly different explanatory variables. The
> response is temperature in fahrenheit (F), and the different models are
> for cities. So each city has its own fitted linear model for
> temperature. I'm assuming that they're independent models for the time
> being, I want to combine the results across all cities and have overall
> prediction intervals. Because I assuming that they're independent can I
> just add together the degrees of freedom from each model (i.e. total
> degrees of freedom=df1+df2+...) and the variance-covariance matrices
> (i.e. V=V1+V2+...) in order to calcalate the overall prediction
> intervals?
>
> Any help would be most appreciated.
>
> Regards,
> Dave
> [[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] plot the y-axis upside down

2011-06-17 Thread Owen, Jason
That's fantastic!  Thanks.


> -Original Message-
> From: Marc Schwartz [mailto:marc_schwa...@me.com]
> Sent: Friday, June 17, 2011 3:47 PM
> To: Owen, Jason
> Cc: 'r-help@r-project.org'
> Subject: Re: [R] plot the y-axis upside down
>
> On Jun 17, 2011, at 2:31 PM, Owen, Jason wrote:
>
> > Hello,
> >
> > I need to create a scatterplot where the y-axis is upside down.  If I
> have non-negative bivariate data in objects "x" and "y," then the
> operation
> >
> > plot(x, -y)
> >
> > gives me the figure I want -- a mirror image of plot(x, y) -- except
> that the y-values (coordinates) are negative, which I don't want.  Is
> there a simple way to do this?
> >
> > Jason
>
>
> This is where the 'ylim' argument to plot is helpful, along with ?rev
> and ?range:
>
>   x <- 1:10
>   y <- 1:10
>   plot(x, y)
>
> versus:
>
>   plot(x, y, ylim = rev(range(y)))
>
> HTH,
>
> Marc Schwartz

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


Re: [R] plot the y-axis upside down

2011-06-17 Thread Marc Schwartz
On Jun 17, 2011, at 2:31 PM, Owen, Jason wrote:

> Hello,
> 
> I need to create a scatterplot where the y-axis is upside down.  If I have 
> non-negative bivariate data in objects "x" and "y," then the operation
> 
> plot(x, -y)
> 
> gives me the figure I want -- a mirror image of plot(x, y) -- except that the 
> y-values (coordinates) are negative, which I don't want.  Is there a simple 
> way to do this?
> 
> Jason


This is where the 'ylim' argument to plot is helpful, along with ?rev and 
?range:

  x <- 1:10
  y <- 1:10
  plot(x, y)

versus:
  
  plot(x, y, ylim = rev(range(y)))

HTH,

Marc Schwartz

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


[R] profile plot in R

2011-06-17 Thread Vickie S

Hi friends,

I have a matrix with following format.

   group var1 var2 ...varN

c1 group1 1.2399 1.4990-1.4829

c2 group4 0.8989 0.7849.1.8933

...

...

c100 group10 .



I want to draw a profile plot
of each condition c1 to c100, which rows in above matrix and each line
representing a row  should be uniquely colored according to the group(1
to 10).

I think this is simple task but I could not figure out how to set the colors.



Any help would be appreciated.



thanks

-Vickie   
[[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] Factor labels

2011-06-17 Thread Bert Gunter
?plotmath

On Fri, Jun 17, 2011 at 6:32 AM, Hugo Loyola  wrote:
> Please, can you help me with the following? I want to include a Greek letter
> as part of a factor label that I need to use as factor on a xyplot. Probably
> this was already solved so can I get the place where I can look for?
>
> Thanks,
>
> Hugo
>
>        [[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.
>



-- 
"Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions."

-- Maimonides (1135-1204)

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.


[R] plot the y-axis upside down

2011-06-17 Thread Owen, Jason
Hello,

I need to create a scatterplot where the y-axis is upside down.  If I have 
non-negative bivariate data in objects "x" and "y," then the operation

plot(x, -y)

gives me the figure I want -- a mirror image of plot(x, y) -- except that the 
y-values (coordinates) are negative, which I don't want.  Is there a simple way 
to do this?

Jason

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


Re: [R] Specify ID variable in daisy{cluster}

2011-06-17 Thread David L Carlson
You need to use hhid as the rownames for housing.cluster rather than
including it as a variable in the data.frame:

housing.cluster <-data.frame(htypec1, afforcr1, resyrc1, crowdcc1, chprbos1)
rownames(housing.cluster) <- hhid

Then it will not be included in the cluster analysis but will be used to
label the dendrogram.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of adlynch
Sent: Thursday, June 16, 2011 12:35 PM
To: r-help@r-project.org
Subject: [R] Specify ID variable in daisy{cluster}

Hi All - I am using the daisy function from the cluster library to create a
dissimilarity matrix.  I'm going to use that matrix to run a cluster
analysis.  My participants are identified with the variable, hhid.  However,
when I try to keep hhid in the dataset that I use to create the
dissimilarity matrix, daisy uses it to create the matrix rather than
ignoring it as an ID variable.  I need to have the ID variable so I can
later on identify which cluster each participant was classified as.  Any
thoughts would be much appreciated!

housing.cluster <-data.frame(hhid, htypec1, afforcr1, resyrc1, crowdcc1,
chprbos1)
housingdiss <- daisy(housing.cluster, metric="gower")


--
View this message in context:
http://r.789695.n4.nabble.com/Specify-ID-variable-in-daisy-cluster-tp3603136
p3603136.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] observation limits on correlog and mantel?

2011-06-17 Thread William M Forney

   Hello,
   I  am working with two datasets with ~5,200 observations.  Apparently,
   neither the correlog function (ncf package) nor the mantel function (ecodist
   package) can handle these datasets.  Does anyone have any experience about
   the  maximum  number of observations these functions can handle?  I am
   considering partitioning them into smaller subsets.
   This would not be an ideal solution as it changes the sampling space and its
   spatial  dependence,  so  other  suggestions  for being able to create
   cross-correlograms are most welcome I am relatively new at doing this
   type of analysis in R.  Thanks.
   Regards, Will.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Server question

2011-06-17 Thread Oliver Jones
Hi

 

A client of mine has asked me to investigate the installation of R-software.

 

Could anyone tell me whether the software works only on a client machine or
whether it sits on a server with clients attaching to it?

 

Not immediately clear from the docs.

 

Best

 

Oliver

--

Oliver Jones

T: 01845 595911
M: 07977 122089

DIG*RED Web Production |   www.digred.com
2 Vyner's Yard
Rainton
North Yorkshire

YO7 3PH

 

 

 

 


[[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] Porting "unmaintained" packages to post R 2.10.0 era

2011-06-17 Thread Stephen Ellison


> -Original Message-
> 
> 
> You can install to any library, even a temporary one that 
> does not need to be in .libPaths() of your regular R 
> installation. So you won't do any harm to your sytsem.
> 

The principal point I was making is that "the manuals" are not very informative 
on the actual build step for a zipped binary and I can see why many find it 
hard to find the guidance they need. If there is a recommended practice - for 
example, what you've just said - why not include it in the manual intended to 
help package developers?

> Why do you want to build a binary before checking? You only 
> need a binary in order to distribute it, and I doubt you want 
> to do that before you checked the package.
> 
I don't want to build a binary before checking, and I didn't suggest that. I 
just wasn't talking about checking, which is well documented. I was talking 
about building zips, which isn't.

Steve E***
This email and any attachments are confidential. Any use...{{dropped:8}}

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


[R] Errorbars

2011-06-17 Thread anna Harris
Hi,

Does anyone know how i get rid of the marker point in my error bars? The
bars default function (it seems) is to have a dot in the middle of the bar,
however i don't want it there.

I am using Hmis to draw my errorbars and code is

a<-as.vector(tapply(Sporangia,list(Host,Isolate),mean))
b<-as.vector(tapply(Sporangia,list(Host,Isolate),sd))
c<-sqrt(b/36)

errbar(c(1.5,2.5,3.5,5.5,6.5,7.5),(tapply(Sporangia,list(Host,Isolate),mean)),a+c,a-c,add=T)

Cheers

Anna

[[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] Size argument in sample function

2011-06-17 Thread alfredo
Hi All,

I'd like to randomly sample a vector N times, where each successive random
sample increases in size. I have realised that the function sample does not
take vectors for arguments. For example,

x<-rnorm(20,0,1)
sample(x,c(1,2,3)) ## will only return one random sample of size 1. 

The trick seems to be getting past the size argument of the function. I've
tried different things without success. Any help would be most appreciated!

Thanks,

A

--
View this message in context: 
http://r.789695.n4.nabble.com/Size-argument-in-sample-function-tp3605486p3605486.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] Will R CMD build delete the .Rnw file?

2011-06-17 Thread Yang Lu
Hi,

I used R CMD build to build a package but realized that the .Rnw file was 
deleted after the .tar.gz file was generated. Is it supposed to be the case? If 
not, any idea as to why it happened?

Thanks,

YL

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 in MAC add many extra <´s

2011-06-17 Thread matto in cor
If the problem is that in the history R adds a new newline avery time, you
should go to Options and activate  "clear input lines" (or something
similar).
marco t.

On Thu, Jun 16, 2011 at 7:38 PM, Jonathan Daily wrote:

> Do you mean prompts (the > that indicates R is waiting for input)?
> Your issue is not clear. Please post a copy/paste of your session, as
> well as your sessionInfo().
>
> On Thu, Jun 16, 2011 at 7:16 AM, Rosario Garcia Gil
>  wrote:
> > Hello
> >
> > I have a annoying problem with R (which I am running in MAC).
> >
> > Every time I enter a function and I press enter to run it, I get many
> additional "<´s", it is really bothering me. I have tried to google to find
> out how to fix the problem but I did not succeed. Anyone with similar
> experience that could help me to change the set ups of the program or
> something.
> >
> > Thanks in advance
> > Rosario
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
>
>
> --
> ===
> Jon Daily
> Technician
> ===
> #!/usr/bin/env outside
> # It's great, trust me.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Ogni tempo ha il suo fascismo. A questo si arriva in molti modi, non
necessariamente col terrore dell'intimidazione poliziesca, ma anche
negando o distorcendo l'informazione, inquinando la giustizia,
paralizzando la scuola, diffondendo in molti sottili modi la
nostalgia per un mondo in cui regnava sovrano l'ordine.
(Primo Levi, 1974)

[[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] Porting "unmaintained" packages to post R 2.10.0 era

2011-06-17 Thread Stephen Ellison
 

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Uwe Ligges
> Sent: 17 June 2011 12:04
> >> See the manual. It tells  you
> >>
> >> R CMD INSTALL --build
> >>
> >> will generate a binary  package.
> >
...
>> it seems I am not the only one to make this mistake:

> 
> We know, and we always ask people to read the recent official 
> manuals where this is mentioned rather than any outdated material.
> 

I appreciate that one is expected to read the manuals, but having re-read the 
current docs I can only say that this information remains very well buried.

Section 1.3 of 'Checking and building packages'  in the present versions of 
'Writing R extensions' starts with the clear statement "Using R CMD build, the 
R package builder, one can build R packages from their sources (for example, 
for subsequent release). "
This tells every package builder that R CMD BUILD is the appropriate route. 
There is no qualifying statement here such as 'For .tar.gz source packages... ' 
or 'except for zipped binaries which should now be built using R CMD INSTALL 
(see below).' And the entire section but for one line describes the use of R 
CMD build.

The one line in that manual that indicates that R CMD INSTALL is preferred 
simply states that "R CMD build can also build pre-compiled version of packages 
for binary distributions, but it is now deprecated in favour of R CMD INSTALL 
--build.". But here, no information is given on what the side effects are. For 
example, it would be reasonable to assume that INSTALL would install the 
package on one's own system, and if one does not intend that it is not at all 
clear what one should do instead. To find the side effects, one has to delve 
into Installation and Administration.

But while R Installation and administration mentions the INSTALL --build 
option, it is under the section "Checking installed source packages" and not 
under 'Installing..." or "Building...". Why would a package developer look 
there at all? They aren't checking an installed package yet. And in that 
section, it is clear that R CMD INSTALL --build is intended to _install check 
and package for distribution_ a package. A prudent package developer should 
surely not want to do all that in one go; they will want to check the package 
using check, build without affecting their current system once the check passes 
and then, if the builds are also successful, check - perhaps by installing from 
the console - that the binary and tar.gz install properly on a system that does 
not already include the package. That careful stepwise process is apparently 
not supported in the documentation under 'checking installed packages' so it's 
easy to see why a developer would not see this section as relev!
 ant even if they had thought to look under a section that seems irrelevant to 
package building.

So while I have every sympathy with R Core being frustrated that users don;t 
read manuals, I do rather think some clearer pointers could be given as to 
where in the manual to look and what to do if one does NOT want to install an 
untested package one one's own live system every time a distribution build is 
desired. Perhaps this has been sorted in the devel tree for 2.14, though?

S Ellison



> Best,
> Uwe Ligges
> 
> 
> > Cheers,
> >
> > Ben
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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 email and any attachments are confidential. Any use...{{dropped:8}}

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


[R] fitting an ARMA model

2011-06-17 Thread Dave Evens
Dear all,
 
I would like to fit an ARMA model, but I'm not sure exactly how to fit it.
 
Here's an example of the problem.
 
This is my time variable, hourly data 
t <- seq(as.POSIXct("2011-01-01 00:00:00"), as.POSIXct("2011-12-31 23:00:00"), 
by="hour")
 
my response
y <- rnorm(length(t), 1000, 500)
 
seasonal factors:
t.h <- as.POSIXlt(t)$hour # hours of the day
t.d <- as.POSIXlt(t)$day  # days of the week
t.m <- as.POSIXlt(t)$mon  # months of the year
 
 
this is my regressor
x.reg <- rnorm(length(t), 10, 1)
 
 
and I have the following auto-regressive lags (1 to 10, 24, and 48 hours)
y.lag1 <- lag(y, 1)
y.lag2 <- lag(y, 2)
y.lag3 <- lag(y, 3)
y.lag4 <- lag(y, 4)
y.lag5 <- lag(y, 5)
y.lag6 <- lag(y, 6)
y.lag7 <- lag(y, 7)
y.lag8 <- lag(y, 8)
y.lag9 <- lag(y, 9)
y.lag10 <- lag(y, 10)
y.lag24 <- lag(y, 24)
y.lag48 <- lag(y, 48)

I want to fit an ARMA with my 3 seasonal factors, 12 lagged variables and the 
regressor against my response variable.
Does someone know how such an ARMA model can be fit?
 
Thank you for your help.
Regards,
Dave
[[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] matching by gender and age

2011-06-17 Thread 1Rnwb
getting errors when running this file  
http://r.789695.n4.nabble.com/file/n3605311/il1ra_status.txt
il1ra_status.txt 


> Age.co<-c(dat2b$Dr_Age)
> Sex.co<-as.factor(dat2b$Sex)
> casecont.co<-as.factor(dat2b$Self_T1D)
> stat.co<-as.factor(dat2b$status)
>
> m <- matchControls(stat.co~Sex.co+Age.co,contlabel="IL1Ra_H")
Error in retval[k] <- controls[which.is.min(d[cases[k], controls])] :
  replacement has length zero
In addition: Warning message:
In min(x, na.rm = TRUE) : no non-missing arguments to min; returning Inf

I would appreciate help to solve this.
Thanks
Sharad 

--
View this message in context: 
http://r.789695.n4.nabble.com/matching-by-gender-and-age-tp3552825p3605311.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] Factor labels

2011-06-17 Thread Hugo Loyola
Please, can you help me with the following? I want to include a Greek letter
as part of a factor label that I need to use as factor on a xyplot. Probably
this was already solved so can I get the place where I can look for?

Thanks,

Hugo

[[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] combining strings

2011-06-17 Thread David L Carlson
You don't say what happens if both arrays have non-missing entries, but
assuming that doesn't happen:

> ifelse(is.na(xf),xg,xf)
 [1] "W" "k" "h" NA  "g" "r" "j" NA  "v" "d" NA  "v" NA  "z" "r" "r" "i"

--
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Erin Hodgess
Sent: Thursday, June 16, 2011 8:59 PM
To: R help
Subject: [R] combining strings

Dear R People:

Suppose I have the following two character vectors:

 xf
 [1] "W" NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
> xg
 [1] NA  "k" "h" NA  "g" "r" "j" NA  "v" "d" NA  "v" NA  "z" "r" "r" "i"
>

I want to end up with

"W" "k" "h" ...

What is the best way to achieve this, please?  I was thinking that if
there is an exclusive "or" that it might work.  I've tried all kinds
of ifs, and ifelse, to no avail.


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.

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


Re: [R] Size argument in sample function

2011-06-17 Thread Marc Schwartz
Just use lapply():

set.seed(1)
x <- rnorm(20)

> lapply(1:3, function(i) sample(x, i))
[[1]]
[1] -0.6264538

[[2]]
[1] -0.3053884 -2.2146999

[[3]]
[1] -2.21469989 -0.30538839 -0.04493361


HTH,

Marc Schwartz


On Jun 17, 2011, at 12:53 PM, Daniel Malter wrote:

> I am sure there is a more elegant version of doing this. But this works:
> 
> x<-rnorm(20)
> y<-matrix(1:5) #number of points to sample
> f<-function(z){sample(x,z)}
> apply(y,1,f)
> 
> Just adjust y to your liking.
> 
> HTH,
> Daniel
> 
> 
> alfredo wrote:
>> 
>> Hi All,
>> 
>> I'd like to randomly sample a vector N times, where each successive random
>> sample increases in size. I have realised that the function sample does
>> not take vectors for arguments. For example,
>> 
>> x<-rnorm(20,0,1)
>> sample(x,c(1,2,3)) ## will only return one random sample of size 1. 
>> 
>> The trick seems to be getting past the size argument of the function. I've
>> tried different things without success. Any help would be most
>> appreciated!
>> 
>> Thanks,
>> 
>> A

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


Re: [R] Size argument in sample function

2011-06-17 Thread Daniel Malter
I am sure there is a more elegant version of doing this. But this works:

x<-rnorm(20)
y<-matrix(1:5) #number of points to sample
f<-function(z){sample(x,z)}
apply(y,1,f)

Just adjust y to your liking.

HTH,
Daniel


alfredo wrote:
> 
> Hi All,
> 
> I'd like to randomly sample a vector N times, where each successive random
> sample increases in size. I have realised that the function sample does
> not take vectors for arguments. For example,
> 
> x<-rnorm(20,0,1)
> sample(x,c(1,2,3)) ## will only return one random sample of size 1. 
> 
> The trick seems to be getting past the size argument of the function. I've
> tried different things without success. Any help would be most
> appreciated!
> 
> Thanks,
> 
> A
> 

--
View this message in context: 
http://r.789695.n4.nabble.com/Size-argument-in-sample-function-tp3605486p3606011.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] issue with strptime

2011-06-17 Thread William Dunlap
You could loop over the list of reasonable formats,
using the first one that works (does not return NA):

f <- function (strings, formats) {
times <- strptime(strings, formats[1])
i <- 1
while ((i < length(formats)) && any(isBad <- is.na(times))) {
i <- i + 1
times[isBad] <- strptime(strings[isBad], formats[i])
}
times
}

E.g.,

> s <- c("2009-04-08 1:49:47 PM",
+"2009-04-08 1:49 PM",
+"2011-06-17 2:01:03 AM")
> fmts <- c("%Y-%m-%d %I:%M:%S %p", "%Y-%m-%d %I:%M %p")
> f(s, fmts)
[1] "2009-04-08 13:49:47" "2009-04-08 13:49:00" "2011-06-17 02:01:03"

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of cassie jones
> Sent: Friday, June 17, 2011 9:55 AM
> To: r-help@r-project.org
> Subject: [R] issue with strptime
> 
> Hi everyone,
> 
> I have bunch of date and time observations in the format 
> %Y-%m-%d %I %M %S
> %p. I used strptime() to read this format. But the problem is 
> some of the
> times are in the format of  %I %M %p, so for those times, 
> strptime is giving
> me NA values.
> 
> For example,
> 
> strptime(paste("2009-04-08","1:49:47 PM"),format="%Y-%m-%d 
> %I:%M:%S %p")
> 
> [1] "2009-04-08 13:49:47"
> 
> 
> But
> 
> strptime(paste("2009-04-08","1:49 PM"),format="%Y-%m-%d %I:%M:%S %p")
> 
> [1] NA
> 
> Now I have approximately 1 observations, so I can't go 
> through all the
> observations individually in order to find which row in the 
> array has this
> format.
> 
> Can anyone suggest me how to handle this issue? Is there any 
> way to convert
> %I %M %p format to %I %M %S %p?
> 
> Thanks in advance for the help.
> 
> Cassie
> 
>   [[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] issue with strptime

2011-06-17 Thread cassie jones
Hi everyone,

I have bunch of date and time observations in the format %Y-%m-%d %I %M %S
%p. I used strptime() to read this format. But the problem is some of the
times are in the format of  %I %M %p, so for those times, strptime is giving
me NA values.

For example,

strptime(paste("2009-04-08","1:49:47 PM"),format="%Y-%m-%d %I:%M:%S %p")

[1] "2009-04-08 13:49:47"


But

strptime(paste("2009-04-08","1:49 PM"),format="%Y-%m-%d %I:%M:%S %p")

[1] NA

Now I have approximately 1 observations, so I can't go through all the
observations individually in order to find which row in the array has this
format.

Can anyone suggest me how to handle this issue? Is there any way to convert
%I %M %p format to %I %M %S %p?

Thanks in advance for the help.

Cassie

[[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] Discrete Test in R

2011-06-17 Thread Jim Silverton
I am looking for a discrete test for testing SNP data. Is ther any common
ones on the market for the 2 x 3 SNP table? I don't want to use the
Chi-square test.
-- 
Thanks,
Jim.

[[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] Multiply list objects

2011-06-17 Thread Uwe Ligges
I still do not get the point for what task this expansion of data may be 
useful, by I guess you want (in this case probably very inefficient, but 
other can work out how to improve if interested) to insert after


k <- lapply(h, function (x) x*0)

the lines:

for(i in seq_along(k)){
temp <- rep(k[i], ncol(k[[i]]))
names(temp) <- colnames(k[[i]])
k[i] <- list(temp)
for(j in seq_along(colnames(h[[i]]))){
k[[i]][[j]][j,] <- k[[i]][[j]][,j] <- h[[i]][,j]
}
}


Uwe Ligges




On 17.06.2011 13:48, Mathijs de Vaan wrote:

Sorry, forgot to quote:

Hi,

I am trying to use the objects from the list below to create more objects.
For each year in h I am trying to create as many objects as there are B's
keeping only the values of B. Example for 1999:

$`1999`$`8025`
   B
B  8025 8026 8027 8028 8029
   802511100
   802610000
   802710000
   802800000
   802900000

$`1999`$`8026`
   B
B  8025 8026 8027 8028 8029
   802501000
   802611101
   802701000
   802800000
   802901000

$`1999`$`8027`
   B
B  8025 8026 8027 8028 8029
   802500100
   802600100
   802711101
   802800000
   802900100

$`1999`$`8028`
   B
B  8025 8026 8027 8028 8029
   802500000
   802600000
   802700000
   802800011
   802900010

$`1999`$`8029`
   B
B  8025 8026 8027 8028 8029
   802500000
   802600001
   802700001
   802800001
   802901111

Any suggestions? You help is very much appreciated!

DF = data.frame(read.table(textConnection("  A  B  C
80  8025  1995
80  8026  1995
80  8029  1995
81  8026  1996
82  8025  1997
82  8026  1997
83  8025  1997
83  8027  1997
90  8026  1998
90  8027  1998
90  8029  1998
84  8026  1999
84  8027  1999
85  8028  1999
85  8029  1999"),head=TRUE,stringsAsFactors=FALSE))

e<- function(y) crossprod(table(DF[DF$C %in% y, 1:2]))
years<- sort(unique(DF$C))
f<- as.data.frame(embed(years, 3))
g<-lapply(split(f, f[, 1]), e)
h<-lapply(g, function (x) ifelse(x>0,1,0))



2011/6/17 Uwe Ligges


Since this example is not reproducible (and you have not quuoted any former
code) I can only give advice "in principle":

1. Never use 1:length(x) since this will seriously fail if x is a length 0
object. Instead, use seq_along(x)
2. If k is a list, then you probably want to use doubled brackets in
k[[year]] for a scalar valued "year".

Uwe Ligges




On 16.06.2011 23:49, mdvaan wrote:


I am still thinking about this problem. The solution could look something
like this (it's net yet working):

k<-lapply(h, function (x) x*0) # I keep the same format as h, but set all
values to 0
years<-c(1997:1999) # I define the years
for (t in 1:length(years))
{
year = as.character(years[t])
ids = rownames(h[year][[1]])
}
for (m in 1:length(relevant_firms))
{
k[year][[m]]<-lapply(k[year], function (col)
k[year][[1]][,m] =
h[year][[1]][,m]&   k[year][[1]][m,] = h[year][[1]][m,])
} # I am creating new list objects that should look like
this
k$'1999'$'8029' and I replace the values in the 8029 column and row by the
original ones in h

Any takes on this problem? Thank you very much!

Best


--
View this message in context: http://r.789695.n4.nabble.com/**
Multiply-list-objects-**tp3595719p3603871.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] texi2dvi runs but produces no output

2011-06-17 Thread christiaan pauw
Thanks Uwe

I have installed R in a path without spaces ( c:\R\R-2.13.0 ..) and ten
installed patchDVI
I Then rAn the command provided by Duncan on a file known to be correct from
the Sweave examples:

>example(Sweave)
(lots of output)
and then

>patchDVI::SweavePDF("Sweave-test-1.tex")
"C:\PROGRA~1\MIKTEX~1.9\miktex\bin\texi2dvi.exe" --version

"C:\PROGRA~1\MIKTEX~1.9\miktex\bin\texi2dvi.exe"  --pdf
--tex-option=-synctex=-1 "Sweave-test-1.tex"  -I
"C:/R/R-2.13.0/share/texmf/tex/latex" -I
"C:/R/R-2.13.0/share/texmf/bibtex/bst"

0 patches made. Did you set \SweaveOpts{concordance=TRUE}?

Is it the fact that Miktex is still in path containing spaces that is
causing this?

best  regrads
Christiaan


2011/6/17 Uwe Ligges 

>
>
> On 17.06.2011 09:24, christiaan pauw wrote:
>
>> Thanks for the advice. I tried to install the package as instructed.
>> Command
>> and results below:
>>
>
> The problem is that the Windows binary of that package is really not
> available on R-Forge.
>
> You can install from sources if you ask R to:
>
> install.packages("patchDVI", 
> repos="http://R-Forge.R-**project.org",
> type="source")
>
> given you have the Rtools installed.
>
>
>

[[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] Porting "unmaintained" packages to post R 2.10.0 era

2011-06-17 Thread Uwe Ligges



On 17.06.2011 14:39, Stephen Ellison wrote:




-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of Uwe Ligges
Sent: 17 June 2011 12:04

See the manual. It tells  you

R CMD INSTALL --build

will generate a binary  package.



...

it seems I am not the only one to make this mistake:




We know, and we always ask people to read the recent official
manuals where this is mentioned rather than any outdated material.



I appreciate that one is expected to read the manuals, but having re-read the 
current docs I can only say that this information remains very well buried.

Section 1.3 of 'Checking and building packages'  in the present versions of 'Writing R 
extensions' starts with the clear statement "Using R CMD build, the R package 
builder, one can build R packages from their sources (for example, for subsequent 
release). "
This tells every package builder that R CMD BUILD is the appropriate route. 
There is no qualifying statement here such as 'For .tar.gz source packages... ' 
or 'except for zipped binaries which should now be built using R CMD INSTALL 
(see below).' And the entire section but for one line describes the use of R 
CMD build.

The one line in that manual that indicates that R CMD INSTALL is preferred simply states 
that "R CMD build can also build pre-compiled version of packages for binary 
distributions, but it is now deprecated in favour of R CMD INSTALL --build.". But 
here, no information is given on what the side effects are. For example, it would be 
reasonable to assume that INSTALL would install the package on one's own system, and if 
one does not intend that it is not at all clear what one should do instead. To find the 
side effects, one has to delve into Installation and Administration.

But while R Installation and administration mentions the INSTALL --build option, it is under the section 
"Checking installed source packages" and not under 'Installing..." or 
"Building...". Why would a package developer look there at all? They aren't checking an 
installed package yet. And in that section, it is clear that R CMD INSTALL --build is intended to 
_install check and package for distribution_ a package. A prudent package developer should surely not 
want to do all that in one go; they will want to check the package using check, build without affecting 
their current system once the check passes and then, if the builds are also successful, check - perhaps 
by installing from the console - that the binary and tar.gz install properly on a system that does not 
already include the package. That careful stepwise process is apparently not supported in the 
documentation under 'checking installed packages' so it's easy to see why a developer would not see this 
section as rel

evant even if they had thought to look under a section that seems irrelevant to 
package building.


So while I have every sympathy with R Core being frustrated that users don;t 
read manuals, I do rather think some clearer pointers could be given as to 
where in the manual to look and what to do if one does NOT want to install an 
untested package one one's own live system every time a distribution build is 
desired. Perhaps this has been sorted in the devel tree for 2.14, though?



You can install to any library, even a temporary one that does not need 
to be in .libPaths() of your regular R installation. So you won't do any 
harm to your sytsem.


Why do you want to build a binary before checking? You only need a 
binary in order to distribute it, and I doubt you want to do that before 
you checked the package.


Best,
Uwe





S Ellison




Best,
Uwe Ligges



Cheers,

Ben


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 email and any attachments are confidential. Any u...{{dropped:8}}


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


Re: [R] Rcmdr Plugin error

2011-06-17 Thread G. Jay Kerns
Dear Erin,

On Fri, Jun 17, 2011 at 1:45 AM, Erin Hodgess  wrote:
> Dear R People: (particularly those who have build Rcmdr Plugin packages):
>
> I'm building a new Plugin and keep getting the following error:
>
>
> Error in if (is.null(where) || where >= n) rbind(object1, object2)
> else if (where <  :
>  missing value where TRUE/FALSE needed
> Error in library(RcmdrPlugin
>
> Have any of you run into this, please?  I feel like I've seen it
> before but can't find the solution.
>
> Thanks,
> Erin
>
>

If I remember correctly, the same thing happened to me when my Plugin
removed a menu which was used (that is, added to) by some other Plugin
(in particular, RcmdrPlugin.IPSUR deleted a menu to which
RcmdrPlugin.HH added a submenu.)

The solution in my case was "don't do that".

Can't really tell whether that problem has anything to do with yours,
but anyway, I hope this helps.
Jay





***
G. Jay Kerns, Ph.D.
Youngstown State University
http://people.ysu.edu/~gkerns/

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


Re: [R] question about split

2011-06-17 Thread Dimitris Rizopoulos

try this:

dat <- data.frame(x = runif(100),
fac1 = rep(c("a", "b", "c", "d"), each = 25),
fac2 = rep(c("A", "B"), 50))

splits <- c("fac1", "fac2")
split(dat, dat[splits])


I hope it helps.

Best,
Dimitris


On 6/17/2011 2:34 PM, carslaw wrote:

Dear R-users

I seem to be stumped on something simple.  I want to split a data frame
by factor levels given in one or more columns e.g. given

dat<- data.frame(x = runif(100),
   fac1 = rep(c("a", "b", "c", "d"), each = 25),
   fac2 = rep(c("A", "B"), 50))

I know I can split it by fac1, fac2 by:

split(dat, list(dat$fac1, dat$fac2))

which gives a list of length 8 - as desired.

My question is, given a vector of column name(s) to split by, how can I
supply
split with these? I was thinking something like:

splits<- c("fac1", "fac2")
split(dat, list(splits))

But that is clearly wrongand I can't see the solution

Many thanks

David Carslaw

Science Policy Group
Environmental Research Group
MRC-HPA Centre for Environment and Health
King's College London
Room 4.129 Franklin Wilkins Building
Stamford Street
London SE1 9NH



--
View this message in context: 
http://r.789695.n4.nabble.com/question-about-split-tp3605281p3605281.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.



--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/

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

2011-06-17 Thread carslaw
Dear R-users

I seem to be stumped on something simple.  I want to split a data frame 
by factor levels given in one or more columns e.g. given

dat <- data.frame(x = runif(100), 
  fac1 = rep(c("a", "b", "c", "d"), each = 25), 
  fac2 = rep(c("A", "B"), 50))

I know I can split it by fac1, fac2 by:

split(dat, list(dat$fac1, dat$fac2))

which gives a list of length 8 - as desired.

My question is, given a vector of column name(s) to split by, how can I
supply
split with these? I was thinking something like:

splits <- c("fac1", "fac2")
split(dat, list(splits))

But that is clearly wrongand I can't see the solution

Many thanks

David Carslaw

Science Policy Group
Environmental Research Group
MRC-HPA Centre for Environment and Health 
King's College London 
Room 4.129 Franklin Wilkins Building 
Stamford Street 
London SE1 9NH 



--
View this message in context: 
http://r.789695.n4.nabble.com/question-about-split-tp3605281p3605281.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] Replacing values without looping

2011-06-17 Thread wuffmeister
Thanks! na.locf was spot on

Very fast approach to this type of problem.

--
View this message in context: 
http://r.789695.n4.nabble.com/Replacing-values-without-looping-tp3602247p3605203.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] Multiply list objects

2011-06-17 Thread Mathijs de Vaan
Sorry, forgot to quote:

Hi,

I am trying to use the objects from the list below to create more objects.
For each year in h I am trying to create as many objects as there are B's
keeping only the values of B. Example for 1999:

$`1999`$`8025`
  B
B  8025 8026 8027 8028 8029
  802511100
  802610000
  802710000
  802800000
  802900000

$`1999`$`8026`
  B
B  8025 8026 8027 8028 8029
  802501000
  802611101
  802701000
  802800000
  802901000

$`1999`$`8027`
  B
B  8025 8026 8027 8028 8029
  802500100
  802600100
  802711101
  802800000
  802900100

$`1999`$`8028`
  B
B  8025 8026 8027 8028 8029
  802500000
  802600000
  802700000
  802800011
  802900010

$`1999`$`8029`
  B
B  8025 8026 8027 8028 8029
  802500000
  802600001
  802700001
  802800001
  802901111

Any suggestions? You help is very much appreciated!

DF = data.frame(read.table(textConnection("  A  B  C
80  8025  1995
80  8026  1995
80  8029  1995
81  8026  1996
82  8025  1997
82  8026  1997
83  8025  1997
83  8027  1997
90  8026  1998
90  8027  1998
90  8029  1998
84  8026  1999
84  8027  1999
85  8028  1999
85  8029  1999"),head=TRUE,stringsAsFactors=FALSE))

e <- function(y) crossprod(table(DF[DF$C %in% y, 1:2]))
years <- sort(unique(DF$C))
f <- as.data.frame(embed(years, 3))
g<-lapply(split(f, f[, 1]), e)
h<-lapply(g, function (x) ifelse(x>0,1,0))



2011/6/17 Uwe Ligges 

> Since this example is not reproducible (and you have not quuoted any former
> code) I can only give advice "in principle":
>
> 1. Never use 1:length(x) since this will seriously fail if x is a length 0
> object. Instead, use seq_along(x)
> 2. If k is a list, then you probably want to use doubled brackets in
> k[[year]] for a scalar valued "year".
>
> Uwe Ligges
>
>
>
>
> On 16.06.2011 23:49, mdvaan wrote:
>
>> I am still thinking about this problem. The solution could look something
>> like this (it's net yet working):
>>
>> k<-lapply(h, function (x) x*0) # I keep the same format as h, but set all
>> values to 0
>> years<-c(1997:1999) # I define the years
>> for (t in 1:length(years))
>>{
>>year = as.character(years[t])
>>ids = rownames(h[year][[1]])
>>}
>>for (m in 1:length(relevant_firms))
>>{
>>k[year][[m]]<-lapply(k[year], function (col)
>> k[year][[1]][,m] =
>> h[year][[1]][,m]&  k[year][[1]][m,] = h[year][[1]][m,])
>>} # I am creating new list objects that should look like
>> this
>> k$'1999'$'8029' and I replace the values in the 8029 column and row by the
>> original ones in h
>>
>> Any takes on this problem? Thank you very much!
>>
>> Best
>>
>>
>> --
>> View this message in context: http://r.789695.n4.nabble.com/**
>> Multiply-list-objects-**tp3595719p3603871.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.
>>
>

[[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] rgeos- installation help

2011-06-17 Thread Roger Bivand
It is very likely that your GEOS installation is too old. Are you trying to
install rgeos 0.1-8, available since yesterday from CRAN? This should check
that GEOS is >= 3.2.2, so perhaps you are trying to install an earlier
version of rgeos? You have not provided your full configure report, so it is
hard to tell. 

In addition to libgeos, you need libgeos-dev and libgeos-c1. 

If you cannot meet the requirement on GEOS from a Debian binary package,
consider installing from source - the Debian binary builds are rather
out-of-date. Be sure to update sp before installing rgeos. Finally, this
question is better suited to R-sig-geo than R-help.

Roger Bivand



Reema Singh wrote:
> 
> Hello Everybody.
> 
> i am installing rgeo in R-2.13 on debian lenny. i am getting following
> error. Can anybody help me why i m not able to compile rgeos.
> 
> rgeos_misc.c: In function ‘rgeos_hausdorffdistance’:
> rgeos_misc.c:55: error: ‘GEOSHausdorffDistance_r’ undeclared (first use in
> this function)
> rgeos_misc.c:55: error: (Each undeclared identifier is reported only once
> rgeos_misc.c:55: error: for each function it appears in.)
> rgeos_misc.c: In function ‘rgeos_hausdorffdistancedensify’:
> rgeos_misc.c:137: error: ‘GEOSHausdorffDistanceDensify_r’ undeclared
> (first
> use in this function)
> make: *** [rgeos_misc.o] Error 1
> ERROR: compilation failed for package ‘rgeos’
> * removing ‘/usr/local/lib/R/site-library/rgeos’
> 
> The downloaded packages are in
> ‘/tmp/RtmptLNmNk/downloaded_packages’
> Warning message:
> In install.packages("rgeos", repos = "http://R-Forge.R-project.org";) :
>   installation of package 'rgeos' had non-zero exit status
> 
> Kind Regards~
> 
> Reema Singh
> 
> 


-
Roger Bivand
Economic Geography Section
Department of Economics
Norwegian School of Economics and Business Administration
Helleveien 30
N-5045 Bergen, Norway

--
View this message in context: 
http://r.789695.n4.nabble.com/rgeos-installation-help-tp3604796p3605030.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] sink() and library() calls cause script to stop when called from php

2011-06-17 Thread Yoni Teitelbaum
Hello all, 


I have a php script that makes a call 


system(PATH_PROJECT_ROOT . '/sh/combineDays.sh ' . $dateString . " " . 
PATH_PROJECT_ROOT); 


and within combineDays.sh I run an R script: 


R --slave --vanilla --args $testDates $BASEDIR $defaultSearchVersion < 
$BASEDIR"R/combineDays.R" 


At the end of this R script, I try to write results to a file, but the script 
seems to stop executing after I call sink(results.file) in the R script. I 
previously observed similar behavior when trying to call library() from within 
the same R script. 


When I run combineDays.sh from the shell, everything works fine. 


Any ideas? 


Thanks. 
[[alternative HTML version deleted]]

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


[R] Hidden Markov Chains - mhsmm

2011-06-17 Thread Lui ##
Dear R-Users,

I am currently trying my luck with Hidden Markov Chains and use the
package mhsmm. I was very "shocked" to see how the initial values for
the transition matrix and probability distributions affected the
outcomes. The results were extremely different even for small changes
in the initial parameter settings. I would usually start with a "rough
guesstimate" which seemed to work quite well:

data.hsmm <- list(x=as.numeric(data),N=nrow(data))
J <- 2 # 2 Regimes
P0 <- matrix(c(0.99,0.01,0.03,0.97), nrow=J,ncol=J)
b0 <- list(mu=c(0.05,-0.05),sigma=c(0.001,0.005)) # first regime has
positive return and lwoer variance than second one; initiating values
init0 <- c(0.5,0.5) # Initial starting probabilities
startval <- hmmspec(init=init0, trans=P0, parms.emis=b0, dens.emis=dnorm.hsmm)
tryCatch(regime <- hmmfit(data.hsmm, startval,
mstep=mstep.norm,tol=1e-10),error=function(err) return(0))

Since it is a larger set of data (several different objects that are
observed) the initial values need to be chosen "across all items to be
evaluated". I did not see any difference when changing the tolerance
or making any changes to the number of "maximal iterations".

Any other package suggestions with which I may avoid this problem? How
are you choosing the "set up variables"?

Thank you very much in advance!

Lui

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


Re: [R] optimization with Sparse matrices

2011-06-17 Thread Ben Bolker
Dube, Jean-Pierre  chicagobooth.edu> writes:

> 
> To whom it may concern,
> 
> I am trying to maximize a log-likelihood function using optim. 
> This is a simple problem with only 18
> parameters.  To conserve memory, I am using sparse matrices 
> (SLAM) for some of the data matrices used in the
> computation of the likelihood.  However, optim appears to
> convert the sparse matrix back to regular data
> format.  This causes me to run out of memory as R tries 
> to create an 8GB matrix.  In short, it does not look as
> though "optim" is compatible with sparse matrices. 
> Does anyone have a suggestion for how I can maximize a
> function in R using sparse matrices for some of the data inputs?
> 

  I wouldn't guess that optim() itself would do any conversion
of the data values (are these passed as additional parameters
or used as global variables?)  The only thing optim() does with
parameters in '...' is pass them along to the objective
function as follows:

fn1 <- function(par) fn(par, ...)

and I can't see a reason that would convert them in any way.
It seems more likely to me (?) that there is some step in 
your objective function where you do an operation that accidentally
converts the sparse back to non-sparse matrices ...

  Can you construct a minimal example that shows this happening?

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


[R] the c implementation of loess

2011-06-17 Thread Saurav Pathak

Hi All,

I am trying to trace the origin of the current loess implementation in 
R.  The reference mentions that Prof Ripley based it on the 1998 version 
of dloess.  When I look at dloess in http://www.netlib.org/a, the file 
"changes" mentions dloess was made available in 1992 and that a memory 
leak was plugged in 1996 with no mention of 1998.  Is there another 
version available?


Thanks,
Saurav

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


Re: [R] Rmpi fails to install

2011-06-17 Thread Hugo Mildenberger
Juergen,

> I try to install Rmpi as root with install.packages("Rmpi").
> It fails with:
> ...

I encountered a similar problem with openmpi-1.5.3 and 
Rmpi_0.5-9.tar.gz. The reason was an unchecked call to 
dlopen("libmpi.so.0").  At least openmpi-1.5.3 does not provide  
"libmpi.so.0" anymore. The patch below corrects for this. 

According to man dlopen, this should work with all POSIX.1-2001 
compliant systems. But possibly R already has an abstraction layer
for loading shared objects?

Here is how to apply this patch locally:

   tar -xvzf Rmpi_0.5-9.tar.gz
   patch -p1 < rmpi-check-dlopen-status.patch
   tar -cvzf  Rmpi_0.5-9a.tar.gz
   R CMD INSTALL --preclean Rmpi_0.5-9a.tar.gz


Best 

Hugo  

 cut 

diff -ru a/Rmpi/src/Rmpi.c b/Rmpi/src/Rmpi.c
--- a/Rmpi/src/Rmpi.c   2010-11-30 20:38:01.0 +0100
+++ b/Rmpi/src/Rmpi.c   2011-06-17 12:48:37.0 +0200
@@ -68,7 +68,11 @@
else {
 
 #ifdef OPENMPI
-   dlopen("libmpi.so.0", RTLD_GLOBAL | RTLD_LAZY);
+   if (!dlopen("libmpi.so", RTLD_GLOBAL | RTLD_LAZY)) { 
+Rprintf("%s\n",dlerror());
+return AsInt(0);
+   }
+
 #endif
 
 #ifndef MPI2

--- cut 






On Monday 07 March 2011 21:53:05 r...@uni-potsdam.de wrote:
> I try to install Rmpi as root with install.packages("Rmpi").
> It fails with:
> ...
> checking for x86_64-pc-linux-gnu-gcc -std=gnu99 option to accept ISO
> C89... none needed
> I am here /usr and it is OpenMPI
> Trying to find mpi.h ...
> Found in /usr/include
> Trying to find libmpi.so or libmpich.a ...
> Found libmpi in /usr/lib
> checking for openpty in -lutil... yes
> checking for main in -lpthread... yes
> configure: creating ./config.status
> config.status: creating src/Makevars
> ** libs
> x86_64-pc-linux-gnu-gcc -std=gnu99 -I/usr/lib64/R/include
> -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\"
> -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -I/usr/include  -DMPI2
> -DOPENMPI -I/usr/local/include-fpic  -march=nocona -O2 -pipe
> -fomit-frame-pointer -c RegQuery.c -o RegQuery.o
> x86_64-pc-linux-gnu-gcc -std=gnu99 -I/usr/lib64/R/include
> -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\"
> -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -I/usr/include  -DMPI2
> -DOPENMPI -I/usr/local/include-fpic  -march=nocona -O2 -pipe
> -fomit-frame-pointer -c Rmpi.c -o Rmpi.o
> x86_64-pc-linux-gnu-gcc -std=gnu99 -I/usr/lib64/R/include
> -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\"
> -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -I/usr/include  -DMPI2
> -DOPENMPI -I/usr/local/include-fpic  -march=nocona -O2 -pipe
> -fomit-frame-pointer -c conversion.c -o conversion.o
> x86_64-pc-linux-gnu-gcc -std=gnu99 -I/usr/lib64/R/include
> -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\"
> -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -I/usr/include  -DMPI2
> -DOPENMPI -I/usr/local/include-fpic  -march=nocona -O2 -pipe
> -fomit-frame-pointer -c internal.c -o internal.o
> x86_64-pc-linux-gnu-gcc -std=gnu99 -shared -Wl,-O1 -Wl,--as-needed -o
> Rmpi.so RegQuery.o Rmpi.o conversion.o internal.o -L/usr/lib -lmpi
> -lutil -lpthread -L/usr/lib64/R/lib -lR
> installing to /usr/lib64/R/library/Rmpi/libs
> ** R
> ** demo
> ** inst
> ** preparing package for lazy loading
> ** help
> *** installing help indices
> ** building package indices ...
> ** testing if installed package can be loaded
> /usr/lib64/R/bin/exec/R: symbol lookup
> error: /usr/lib64/openmpi/mca_paffinity_linux.so: undefined symbol:
> mca_base_param_reg_int
> 
> The downloaded packages are in
>  ?/tmp/RtmpLvvl9R/downloaded_packages?
> Updating HTML index of packages in '.Library'
> Warning message:
> In install.packages("Rmpi") :
>installation of package 'Rmpi' had non-zero exit status
> 
> The system is a gentoo system with openmpi-1.5.1. I am thankful for any
> hint.
> 
> Juergen
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Porting "unmaintained" packages to post R 2.10.0 era

2011-06-17 Thread Uwe Ligges



On 17.06.2011 12:04, Ben Rhelp wrote:

- Original Message 


From: Uwe Ligges
To: Ben Rhelp
Cc: r-help@r-project.org
Sent: Thu, 16 June, 2011 14:38:12
Subject: Re: [R] Porting "unmaintained" packages to post R 2.10.0 era


[...]


What about "--binary is  deprecated"? What is the correct way now?


See the manual. It tells  you

R CMD INSTALL --build

will generate a binary  package.


Hi Uwe,

Thanks a lot for this. I hope Google will rank your reply because it seems I am
not the only one to make this mistake:

http://www.biostat.wisc.edu/~kbroman/Rintro/Rwinpack.html
http://robjhyndman.com/researchtips/building-r-packages-for-windows/
http://stevemosher.wordpress.com/step-10-build/



We know, and we always ask people to read the recent official manuals 
where this is mentioned rather than any outdated material.


Best,
Uwe Ligges



Cheers,

Ben


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


Re: [R] Porting "unmaintained" packages to post R 2.10.0 era

2011-06-17 Thread Ben Rhelp
Hi Prof Brian,

Thank you for your email and for writing MASS. This book is brilliant.


- Original Message 
> From: Prof Brian Ripley 
> To: Ben Rhelp 
> Cc: r-help@r-project.org
> Sent: Thu, 16 June, 2011 14:48:00
> Subject: Re: [R] Porting "unmaintained" packages to post R 2.10.0 era
> 
> On Thu, 16 Jun 2011, Mr Rhelp wrote:
> 
[...]
> 
> Sounds  like you are doing this on Windows (please do tell us!) and trying to 
>start with  a Windows binary package.
> 

Yes, sorry about that:
> version
   _
platform   x86_64-pc-mingw32
arch   x86_64   
os mingw32  
system x86_64, mingw32  
status  
major  2
minor  13.0 
year   2011 
month  04   
day13   
svn rev55427
language   R
version.string R version 2.13.0 (2011-04-13)

[...]

> > Is there a HOWTO/porting  guide for packages pre R 2.10.0 to post R 2.10.0?
> 
> You don't need  one.  You start with the package sources, and install those.  
>If you  don't have the sources, you ask the author for the sources.  But on 
>the  
>page you mention, I see
> 
> 'unix/macs use the  *.tar.gz  version'
> 
> by which they mean 'the source package'.
> 
> (Note that for  GPLed packages such as this one, the sources must be made  
>available.)
> 
> There are some errors in the format of the Rd files, but both  packages 
> install 
>in R 2.13.0.  However, you are supposed to get Java  components from a site 
>which no longer exists, so I think you are going to need  to ask the author 
>for 
>help.
> 
> One advantage of recent R is that to install  packages like these from the 
>sources you just need R, so there is no reason to  distribute Windows binary 
>packages (for such packages, with no C/C++/Fortran  code).
> 

Ok, my thinking was completely wrong. Your response help me to get things 
working. I have updated the packages to work with the latest version of the 
third party software (SoNIA) and I have contacted the original author with the 
aim to distribute some updated versions of the packages.
[...]

Thanks a lot again for your help.

Best regards,

Ben


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


Re: [R] Porting "unmaintained" packages to post R 2.10.0 era

2011-06-17 Thread Ben Rhelp
- Original Message 

> From: Uwe Ligges 
> To: Ben Rhelp 
> Cc: r-help@r-project.org
> Sent: Thu, 16 June, 2011 14:38:12
> Subject: Re: [R] Porting "unmaintained" packages to post R 2.10.0 era
> 
[...]
> >
> > What about "--binary is  deprecated"? What is the correct way now?
> 
> See the manual. It tells  you
> 
> R CMD INSTALL --build
> 
> will generate a binary  package.

Hi Uwe,

Thanks a lot for this. I hope Google will rank your reply because it seems I am 
not the only one to make this mistake:

http://www.biostat.wisc.edu/~kbroman/Rintro/Rwinpack.html
http://robjhyndman.com/researchtips/building-r-packages-for-windows/
http://stevemosher.wordpress.com/step-10-build/

Cheers,

Ben

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


Re: [R] Replacing values without looping

2011-06-17 Thread Petr PIKAL
Hi

> Hi,
> 
> If you truly have an array, this is option that should be much faster
> than a loop:
> 
> index <- which(is.na(dat))
> dat[index] <- dat[index - 1]
> 
> the only catch is that when there previous value is NA, you may have
> to go through the process a few times to get them all.  One way to
> automate this would be:
> 
> index <- which(is.na(dat))
> 
> while (any(index)) {
>   dat[index] <- dat[index - 1]
>   index <- which(is.na(dat))
> }
> 
> If your dataset has many adjacent missing values, then it would be
> worth it to use a fancier technique that looks for the first previous
> nonmissing value.  There could even be a clever way with indexing that
> I am missing.

Package zoo and function ?na.locf can be used for this type of task.

Regards
Petr


> 
> HTH,
> 
> Josh
> 
> On Thu, Jun 16, 2011 at 5:13 AM, wuffmeister  wrote:
> > I got an array similar to the one below, and want to replace all NAs 
with the
> > previous value.
> > 99 8.2 b
> > NA 8.3 x
> > NA 7.9 x
> > 98 8.1 b
> > NA 7.7 x
> > 99 9.3 b
> > ...
> >
> > i.e. the first two NAs should be replaced to 99, whereas the last one 
should
> > be 98.
> >
> > I would like to apply a function to reach row, checking if the value 
in col
> > 1 is NA, and if it is, set the value to the previous row's col 1 
value.
> >
> > Haven't been able to do this without looping, which gets very slow for 
large
> > datasets...
> >
> > --
> > View this message in context: http://r.789695.n4.nabble.com/Replacing-
> values-without-looping-tp3602247p3602247.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.
> >
> 
> 
> 
> -- 
> Joshua Wiley
> Ph.D. Student, Health Psychology
> University of California, Los Angeles
> http://www.joshuawiley.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] Polygon question

2011-06-17 Thread Uwe Ligges
Well you need to recalculate the x values and need to interpolate for 
the position where you lines cross the m lines 


Uwe Ligges




On 16.06.2011 23:35, Muhammad Rahiz wrote:

Hi all,

I have the following script which fills the values which are less than
the mean of a given timeseries.

If you look closely, the colored regions are "out of line".

Any suggestions how I can rectify this?

Thanks

Muhammad


# -
#rm(list=ls())

x <- abs(rnorm(100))
tt <- 1:100

m <- mean(x)
w <- which(x>=m)

x1 <- x ; x2 <- x ; x3 <- x
x1[w] <- m
x2[1:length(x)] <- m

tx <- c(tt,rev(tt)) ; ty <- c(x1,rev(x2))

par(mfrow=c(2,1))
yy <- c(0,3) # y-limit

plot(tt,x,type="l",ylim=yy)
abline(h=m)

plot(tx,ty,type="n",ylim=yy)
polygon(tx,ty,col="red")
lines(x)
# -

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] texi2dvi runs but produces no output

2011-06-17 Thread Uwe Ligges



On 17.06.2011 09:24, christiaan pauw wrote:

Thanks for the advice. I tried to install the package as instructed. Command
and results below:


install.packages("patchDVI", repos="http://R-Forge.R-project.org";)

Installing package(s) into ‘C:/Users/nova/Documents/R/win-library/2.13’
(as ‘lib’ is unspecified)
Warning message:
In getDependencies(pkgs, dependencies, available, lib) :
   package ‘patchDVI’ is not available (for R version 2.13.0)



The problem is that the Windows binary of that package is really not 
available on R-Forge.


You can install from sources if you ask R to:

install.packages("patchDVI", repos="http://R-Forge.R-project.org";, 
type="source")


given you have the Rtools installed.




I then ran the tests in Rtools.


Which tests in Rtools???


I suspect the fact that I have I have
installed R in a path containing spaces may be the problem - maybe also for


Paths with spaces generate problems for LaTeX and R tries to work 
around, but may fail.



Not sure why you do the stuff below at all and why R cannot change the 
working directory.


Uwe Ligges



the Sweave part. Is there any other remedy but to re-install R or can I
insert a link in a path without spaces  ?


  library("tools")
  testInstalledBasic("both")

>

running strict specific tests
   running code in ‘eval-etc.R’
unable to open output file
FAILED
[1] 1
Warning message:
running command '"C:/PROGRA~1/R/R-213~1.0/bin/i386/R" CMD BATCH --vanilla
--no-timing "eval-etc.R" "eval-etc.Rout"' had status 2

  testInstalledPackages("base")

Error in setwd(outDir) : cannot change working directory

  testInstalledPackages("recommended")

Error in setwd(outDir) : cannot change working directory



On 16 June 2011 14:10, Duncan Murdoch  wrote:


On 11-06-16 7:50 AM, christiaan pauw wrote:


Hi everybody.

Was the problem below ever solved? I have the same problem on Windows 7
with
R 2.13.0 and LyX 2 - everything freshly installed. My Rweave.bat and
MakeSweave.R files are similar to below (I followed
http://wiki.lyx.org/uploads/**LaTeX/SweaveR/lyx_with_r_and_**
sweave_instructions.pdf
)



I don't use LyX or that batch file, I use some code I wrote that's in the
patchDVI package 
(https://r-forge.r-project.**org/R/?group_id=233)
that I wrote.  You might want to try it.

The single line to run Sweave and pdflatex is

Rscript -e "patchDVI::SweavePDF( '$1' )"

where $1 is the name of the .Rnw file.  If that doesn't work for you, I
might be able to help with debugging.

Duncan Murdoch




[[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] Multiply list objects

2011-06-17 Thread Uwe Ligges
Since this example is not reproducible (and you have not quuoted any 
former code) I can only give advice "in principle":


1. Never use 1:length(x) since this will seriously fail if x is a length 
0 object. Instead, use seq_along(x)
2. If k is a list, then you probably want to use doubled brackets in 
k[[year]] for a scalar valued "year".


Uwe Ligges



On 16.06.2011 23:49, mdvaan wrote:

I am still thinking about this problem. The solution could look something
like this (it's net yet working):

k<-lapply(h, function (x) x*0) # I keep the same format as h, but set all
values to 0
years<-c(1997:1999) # I define the years
for (t in 1:length(years))
{
year = as.character(years[t])
ids = rownames(h[year][[1]])
}
for (m in 1:length(relevant_firms))
{
k[year][[m]]<-lapply(k[year], function (col) k[year][[1]][,m] =
h[year][[1]][,m]&  k[year][[1]][m,] = h[year][[1]][m,])
} # I am creating new list objects that should look like this
k$'1999'$'8029' and I replace the values in the 8029 column and row by the
original ones in h

Any takes on this problem? Thank you very much!

Best


--
View this message in context: 
http://r.789695.n4.nabble.com/Multiply-list-objects-tp3595719p3603871.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] problem with missing package

2011-06-17 Thread Uwe Ligges



On 16.06.2011 16:19, Eric Elguero wrote:

Hi everybody,

I just tried to run R on one of my projects
but it did not want to run:



R version 2.12.1 (2010-12-16)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-linux-gnu (64-bit)



Loading required package: utils
Error in loadNamespace(i[[1L]], c(lib.loc, .libPaths())) :
   there is no package called 'nlme'
Fatal error: unable to restore saved data in .RData


there are two things I do not understand:

i) I had actually nlme installed, and working,
but when I look in /usr/lib/R/library/nlme
I find only a text file named "COPYING"
and containing the gnu license.
Where is the package gone? (by itself)



We do not know.


ii) I tried to reinstall nlme but could not
find it in the usual repositories.


There is a recent version in the source repository that depends on R >= 
2.13.0, hence yo either need to grab a version from the archives or even 
better just upgrade R which ships with nlme.


Uwe Ligges



in any case, I would like to recover at least those R objects
that do not depend on nlme.

I tried :

$mv .RData xxx
$R

load("xxx")


but that doesn't help.

Is there a method to extract some information from .RData
without loading it?

Eric Elguero

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

2011-06-17 Thread Iasonas Lamprianou
Thank you for all the previous support. I have another question:

I am using eRm to run a partial credit model. Is there a way to ask eRm
to compute and present to me the probability of a person with a specific
ability to achieve each one of the scores 0, 1, 2, 3, or 4 on a specific
question with known step measures (thresholds)? I checked the documentation
but there is no relevant info. (actually, it says that only in the case of the 
simple Rasch model has the prediction function been written - but again, how 
are the residuals computed if such a function does not exist?)

 
Thank you for your time
 
Dr. Iasonas Lamprianou
Department of Social and Political Sciences
University of Cyprus
[[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] prediction intervals

2011-06-17 Thread Dave Evens
Thank you for your post Greg.
Do you have any useful references regarding this variability (papers etc)?
 
Many thanks.
Dave

From: Greg Snow 
To: Dave Evens ; "r-help@r-project.org" 

Sent: Thursday, 16 June 2011, 21:32
Subject: RE: [R] prediction intervals

I don't think that this approach is appropriate here.  Each iteration after the 
1st the lm/predict combination will assume that the new data is exact when in 
fact it is an estimate with some error involved.  To properly do this you need 
to take into account that variability.  There is a time series task view on 
CRAN that may point you to better tools.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Dave Evens
> Sent: Thursday, June 16, 2011 11:33 AM
> To: r-help@r-project.org
> Subject: [R] prediction intervals
> 
> 
> 
> Dear members,
> 
> I'm fitting linear model using "lm" which has numerous auto-regressive
> terms as well as other explanatory variables. In order to calculate
> prediction intervals, i've used a for-loop as the auto-regressive
> parameters need to be updated each time so that a new forecast and
> corresponding prediction interval can be calculated.
> 
> I'm fitting a number of these models which have different values for
> the response variable and possibly different explanatory variables. The
> response is temperature in fahrenheit (F), and the different models are
> for cities. So each city has its own fitted linear model for
> temperature. I'm assuming that they're independent models for the time
> being, I want to combine the results across all cities and have overall
> prediction intervals. Because I assuming that they're independent can I
> just add together the degrees of freedom from each model (i.e. total
> degrees of freedom=df1+df2+...) and the variance-covariance matrices
> (i.e. V=V1+V2+...) in order to calcalate the overall prediction
> intervals?
> 
> Any help would be most appreciated.
> 
> Regards,
> Dave
>     [[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] NonParametric Anova

2011-06-17 Thread Daniel Malter
A function for non-parametric multivariate analysis of variance (should do
univariate, too, I guess)  allowing for interactions (as far as I can tell)
is implemented in the anosim() function of the "vegan" package.

See also:

http://cc.oulu.fi/~jarioksa/opetus/metodi/vegantutor.pdf

http://cran.r-project.org/web/packages/vegan/vegan.pdf

http://onlinelibrary.wiley.com/doi/10./j.1442-9993.2001.01070.pp.x/full

HTH,
Daniel






Loo Yim Ling wrote:
> 
> Dear Sir,
> 
> I would like to ask whether there is any tool in R, developed for the
> function of non parametric Anova, where the non parametric analysis is
> able to compute the p-value for interaction as well (similar to Anova)? If
> not, would sir like to suggest any of the other statistical software
> around which would have this tool?
> Thank you.
> 
> LYLing.
> 
> “SAVE PAPER! SAVE THE WORLD! - Please do not print this e-mail unless
> necessary”
> 
> This e-mail and the attachments are intended solely for the person to whom
> it has been addressed. It contains privileged and/or confidential
> information and is privileged or otherwise protected from disclosure. If
> you are not the person for whom this e-mail was intended, or the e-mail
> has reached you by mistake, please delete it immediately and
> inform us of the error. Our e-mail address is administra...@uniten.edu.my.
> 
> All opinions, conclusions and other information in this message that do
> not relate to the official business of Universiti Tenaga Nasional (UNITEN)
> shall be understood as neither given nor endorsed by UNITEN. UNITEN shall
> not be responsible for any activity that may be considered as illegal
> and/or improper use of e-mail and UNITEN further disclaims and shall not
> accept liability for any content of this e-mail, or for the consequences
> of any actions taken on the basis of the information provided, unless that
> information is subsequently confirmed in writing.
> 
> WARNING
> Internet communications cannot be guaranteed to be secured or error-free
> as information could be intercepted, corrupted, lost, arrive late or
> contain viruses. As such, we do not accept liability for any errors or
> omissions in the content of this message which may arise as a result of
> internet transmission.
> 
> UNITEN does not authorize any of its employees to make any defamatory or
> seditious statements or commit any offence which is contrary to the laws
> of Malaysia. Any such communications and/or actions by such employees are
> outside the scope of employment of the said individuals and UNITEN shall
> not be liable for such communications and/or actions.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

--
View this message in context: 
http://r.789695.n4.nabble.com/NonParametric-Anova-tp3601876p3604726.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] rgeos- installation help

2011-06-17 Thread Reema Singh
Hello Everybody.

i am installing rgeo in R-2.13 on debian lenny. i am getting following
error. Can anybody help me why i m not able to compile rgeos.

rgeos_misc.c: In function ‘rgeos_hausdorffdistance’:
rgeos_misc.c:55: error: ‘GEOSHausdorffDistance_r’ undeclared (first use in
this function)
rgeos_misc.c:55: error: (Each undeclared identifier is reported only once
rgeos_misc.c:55: error: for each function it appears in.)
rgeos_misc.c: In function ‘rgeos_hausdorffdistancedensify’:
rgeos_misc.c:137: error: ‘GEOSHausdorffDistanceDensify_r’ undeclared (first
use in this function)
make: *** [rgeos_misc.o] Error 1
ERROR: compilation failed for package ‘rgeos’
* removing ‘/usr/local/lib/R/site-library/rgeos’

The downloaded packages are in
‘/tmp/RtmptLNmNk/downloaded_packages’
Warning message:
In install.packages("rgeos", repos = "http://R-Forge.R-project.org";) :
  installation of package 'rgeos' had non-zero exit status

Kind Regards~

Reema Singh

[[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] Hidden Markov Chains - mhsmm

2011-06-17 Thread Lui ##
Dear R-Users,

I am currently trying my luck with Hidden Markov Chains and use the
package mhsmm. I was very "shocked" to see how the initial values for
the transition matrix and probability distributions affected the
outcomes. The results were extremely different even for small changes
in the initial parameter settings. I would usually start with a "rough
guesstimate" which seemed to work quite well:

data.hsmm <- list(x=as.numeric(data),N=nrow(data))
J <- 2 # 2 Regimes
P0 <- matrix(c(0.99,0.01,0.03,0.97), nrow=J,ncol=J)
b0 <- list(mu=c(0.05,-0.05),sigma=c(0.001,0.005)) # first regime has
positive return and lwoer variance than second one; initiating values
init0 <- c(0.5,0.5) # Initial starting probabilities
startval <- hmmspec(init=init0, trans=P0, parms.emis=b0, dens.emis=dnorm.hsmm)
tryCatch(regime <- hmmfit(data.hsmm, startval,
mstep=mstep.norm,tol=1e-10),error=function(err) return(0))

Since it is a larger set of data (several different objects that are
observed) the initial values need to be chosen "across all items to be
evaluated". I did not see any difference when changing the tolerance
or making any changes to the number of "maximal iterations".

Any other package suggestions with which I may avoid this problem? How
are you choosing the "set up variables"?

Thank you very much in advance!

Lui

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


Re: [R] texi2dvi runs but produces no output

2011-06-17 Thread christiaan pauw
Thanks for the advice. I tried to install the package as instructed. Command
and results below:

> install.packages("patchDVI", repos="http://R-Forge.R-project.org";)
Installing package(s) into ‘C:/Users/nova/Documents/R/win-library/2.13’
(as ‘lib’ is unspecified)
Warning message:
In getDependencies(pkgs, dependencies, available, lib) :
  package ‘patchDVI’ is not available (for R version 2.13.0)

I then ran the tests in Rtools. I suspect the fact that I have I have
installed R in a path containing spaces may be the problem - maybe also for
the Sweave part. Is there any other remedy but to re-install R or can I
insert a link in a path without spaces  ?

>  library("tools")
>  testInstalledBasic("both")
running strict specific tests
  running code in ‘eval-etc.R’
unable to open output file
FAILED
[1] 1
Warning message:
running command '"C:/PROGRA~1/R/R-213~1.0/bin/i386/R" CMD BATCH --vanilla
--no-timing "eval-etc.R" "eval-etc.Rout"' had status 2
>  testInstalledPackages("base")
Error in setwd(outDir) : cannot change working directory
>  testInstalledPackages("recommended")
Error in setwd(outDir) : cannot change working directory



On 16 June 2011 14:10, Duncan Murdoch  wrote:

> On 11-06-16 7:50 AM, christiaan pauw wrote:
>
>> Hi everybody.
>>
>> Was the problem below ever solved? I have the same problem on Windows 7
>> with
>> R 2.13.0 and LyX 2 - everything freshly installed. My Rweave.bat and
>> MakeSweave.R files are similar to below (I followed
>> http://wiki.lyx.org/uploads/**LaTeX/SweaveR/lyx_with_r_and_**
>> sweave_instructions.pdf
>> )
>>
>
> I don't use LyX or that batch file, I use some code I wrote that's in the
> patchDVI package 
> (https://r-forge.r-project.**org/R/?group_id=233)
> that I wrote.  You might want to try it.
>
> The single line to run Sweave and pdflatex is
>
> Rscript -e "patchDVI::SweavePDF( '$1' )"
>
> where $1 is the name of the .Rnw file.  If that doesn't work for you, I
> might be able to help with debugging.
>
> Duncan Murdoch
>
>

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