[R] sample weights in ols

2011-05-09 Thread jour4life
Hello all,

I am wondering if there is a way to specify sampling weights for an ols
model using sample weights.

For instance, right now, my code is:

fit.ex<-lm(y~x1+x2+x3+...xk,data=dataset,weights=weightvariable.)
summary(fit.ex)

But, there is almost no difference in the coefficients nor standard errors.
I am skeptical that I am using the option correctly since many posts state
that the "weights" option is for weighted least squares. Or is this the same
thing?

Any help is appreciated!

Thanks

Carlos

--
View this message in context: 
http://r.789695.n4.nabble.com/sample-weights-in-ols-tp3510865p3510865.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] Setting NA to blank

2011-05-09 Thread Petr PIKAL
Hi

> Re: [R] Setting NA to blank
> 
> I asked because I thought it'd solve an issue I had. I was actually 
being
> quite rash in asking this question and for that, I apologize.
> 
> I wanted to know because I was attempting to create a heatmap where the 
NA
> values would not be shown while all the outputs with actual numerical 
value
> will be shown. I had assumed that setting the NA's to blanks would fix 
the
> issue, but it hadn't. I refrained from immediately asking another 
question
> so I that I can look further into this.

If you used heatmap function from stats package I believe that NA values 
are not displayed so they appear as white. So basically you should not 
need any change.

It is usually better then assume what you think the functions are doing to 
learn what they actually do by consulting help page. 

You could also try examples provided at bottom of almost each help page 
and modify it to suit your needs.

Regards
Petr



> 
> I hope that answers your question.
> 
> On Mon, May 9, 2011 at 4:21 PM, Ted Harding 
wrote:
> 
> > John Kane's reply sums it up! (Though you could use "",
> > instead of " ", which would give you an "empty string"
> > instead of the "space" character; but the resulting
> > matrix would still consist entirely of "character"
> > elements).
> >
> > However, the real reason I am following up is to ask
> > why you want the blank instead of the NA.
> >
> > If it is just for printing out or display, then the
> > fact that the matrix has been converted to character
> > probably does not matter.
> >
> > But if it is for compatibility with some other
> > computational software that (e.g.) expects missing
> > values to be represented by a blank, or some "null"
> > representation, then it may not be so straightforward.
> >
> > So, if that might be an issue, please describe for us
> > how you intend to use the result.
> >
> > Ted.
> >
> > On 09-May-11 19:56:39, Dat Mai wrote:
> > > Thank you kind sir!
> > >
> > > On Mon, May 9, 2011 at 3:25 PM, John Kane  
wrote:
> > >
> > >>
> > >> (mat <- matrix(c(1,2,3,NA),2))
> > >> mat[is.na(mat)]   <- " "
> > >> mat
> > >>
> > >> But if you have a numerical matrix it coverts the matrix to 
character.
> > >>
> > >> --- On Mon, 5/9/11, Dat Mai  wrote:
> > >>
> > >> > From: Dat Mai 
> > >> > Subject: [R]  Setting NA to blank
> > >> > To: r-help@r-project.org
> > >> > Received: Monday, May 9, 2011, 2:46 PM
> > >> > Hey All,
> > >> >
> > >> > I have a matrix m, and I wish to set all the NA values to
> > >> > blank. How would I
> > >> > do so?
> > >> >
> > >> > --
> > >> > Best,
> > >> > Dat Mai
> > >> > PhD Rotation Student
> > >> > Albert Einstein College of Medicine
> >
> > 
> > E-Mail: (Ted Harding) 
> > Fax-to-email: +44 (0)870 094 0861
> > Date: 09-May-11   Time: 21:21:07
> > -- XFMail --
> >
> 
> 
> 
> -- 
> Best,
> Dat Mai
> PhD Rotation Student
> Albert Einstein College of Medicine
> 
>[[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] Installing package

2011-05-09 Thread Hurr
Using install packages pull-down, I chose a mirror and then package rJava.
Then it said that it cannot remove the rJava package already installed.
Then when I typed library(rJava) it said there was no rjava package.
Isn't that rather contradictory for R?


--
View this message in context: 
http://r.789695.n4.nabble.com/Installing-package-tp3510987p3510987.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] Weird read.xls behavior

2011-05-09 Thread Jun Shen
Kenneth,

Thanks for the reply. I checked the original data. There is no space. I even
manually added a space to one value. After reading in with read.xls, the
value has two spaces. The reason I don't like it is I am going to do some
comparison with another dataset, which is supposed to be the same as this
one. Now I am getting a bunch of false negatives.

Jun

On Mon, May 9, 2011 at 11:01 PM, Kenneth Roy Cabrera Torres <
krcab...@une.net.co> wrote:

> Maybe in the original there are some "ghost" spaces after ng/ml,
> verify them.
>
> Any way you can erase the first and the last white spaces with gsub
> function.
>
> HTH
>
> Kenneth
> El lun, 09-05-2011 a las 22:44 -0500, Jun Shen escribió:
> > Dear list,
> >
> > I used read.xls to read in an excel file, which has both character and
> > numeric columns. Everything seems fine except in the last column, I have
> > this character value "ng/ml". When reading in, read.xls seems to add a
> space
> > at the end of it, became "ng/ml ". How can I prevent read.xls doing so?
> > Thanks.
> >
> > >read.xls(data, header=T, as.is=T)
> >
> > Jun
> >
> >   [[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] Weird read.xls behavior

2011-05-09 Thread Kenneth Roy Cabrera Torres
Maybe in the original there are some "ghost" spaces after ng/ml, 
verify them.

Any way you can erase the first and the last white spaces with gsub
function.

HTH

Kenneth
El lun, 09-05-2011 a las 22:44 -0500, Jun Shen escribió:
> Dear list,
> 
> I used read.xls to read in an excel file, which has both character and
> numeric columns. Everything seems fine except in the last column, I have
> this character value "ng/ml". When reading in, read.xls seems to add a space
> at the end of it, became "ng/ml ". How can I prevent read.xls doing so?
> Thanks.
> 
> >read.xls(data, header=T, as.is=T)
> 
> Jun
> 
>   [[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] Weird read.xls behavior

2011-05-09 Thread Jun Shen
Dear list,

I used read.xls to read in an excel file, which has both character and
numeric columns. Everything seems fine except in the last column, I have
this character value "ng/ml". When reading in, read.xls seems to add a space
at the end of it, became "ng/ml ". How can I prevent read.xls doing so?
Thanks.

>read.xls(data, header=T, as.is=T)

Jun

[[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] SQP with Constraints

2011-05-09 Thread Ravi Varadhan
Look at the solve.QP() function in the "quadprog" package.  

Ravi.

From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of 
vioravis [viora...@gmail.com]
Sent: Monday, May 09, 2011 10:46 PM
To: r-help@r-project.org
Subject: [R] SQP with Constraints

I am trying to optimize  function similar to the following:

Minimize x1^2 - x2^2 - x3^2

st x1 < x2
x2 < x3

The constraint is that the variables should be monotonically increasing. Is
there any package that implements Sequential Quadratic Programming with
ability include these constraints???

Thanks you.

Ravi

--
View this message in context: 
http://r.789695.n4.nabble.com/SQP-with-Constraints-tp3510857p3510857.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] SQP with Constraints

2011-05-09 Thread vioravis
I am trying to optimize  function similar to the following:

Minimize x1^2 - x2^2 - x3^2

st x1 < x2
x2 < x3

The constraint is that the variables should be monotonically increasing. Is
there any package that implements Sequential Quadratic Programming with
ability include these constraints??? 

Thanks you.

Ravi

--
View this message in context: 
http://r.789695.n4.nabble.com/SQP-with-Constraints-tp3510857p3510857.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] Saving multiple 3x3 TIFF graphics inside a loop

2011-05-09 Thread John S
Dear Friends,

I have been trying to save multiple 3x3 (mfrow=c(3,3) graphics inside a loop
using tiff figure format (not using PDF or savePlot functions) with no
success. Could you please help?

Here is a simplified example code:



dat=data.frame (ID=rep(1:10,each=10),IDV=rep(seq(1:10),times=10))

dat$DV <- with(dat, 50+15*IDV)

dat=dat[order(dat$ID,dat$IDV),]

for(i in 1:10){

   dt1 = dat[dat$ID==i,]

   pagei=as.integer(ceiling(i/9))

   #This does not work

   if(i==1) {tiff(file=paste("Outfile",pagei,".tiff",sep="")

 ,width=17.15,height=17.15,units="cm", res=1200, pointsize=10,
compression = "lzw")}

  if(i==10) {tiff(file=paste("Outfile",pagei,".tiff",sep="")

 ,width=17.15,height=17.15,units="cm", res=1200, pointsize=10,
compression = "lzw")}

   par(mar=c(5,5,4,1),mfrow=c(3,3))

   plot(dt1[, "IDV"],dt1[, "DV"], type="n")

   lines(dt1[, "IDV"], dt1[, "DV"], type="b", col=1,lwd=3,pch=1)

   title(paste(i),col=8,cex=.8)

 if(i==9) dev.off ## close file

}

dev.off()

 The idea is to save 2 files with 3x3 layouts but I only get one subject in
Outfile1.



OS: Windows 7 64 bits

R version 2.13.0

Many Thanks,

John

[[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] save and load user modifications of options

2011-05-09 Thread xue wang
Thanks David! I got a solution, though maybe not optimal.  In the zzz.r file
of the R package, I include the folloing code:

.onLoad <- function(libname,pkgname) {
myoptions <- list(ngs.python="sage -python",ngs.macs="macs14")
if(exists("myoptions",.GlobalEnv))
options(.GlobalEnv$myoptions)
else
options(myoptions)
}
If user save his options in the myoptions list, by loading saved image he
does not need to set the option again. However, I still believe there is a
more elegant way to let user save his options. Hope someone could come up
with a better solution :-)

Thanks!


Xue




On Sat, May 7, 2011 at 5:47 AM, David Winsemius wrote:

>
> On May 6, 2011, at 8:59 PM, xwang14 wrote:
>
> Hi,
>>
>> Could anyone help me with the following problem? After I finished a R
>> session and modified some options (for example, set
>> options(editor="neditor")), I want save these modifications so that after
>> I
>> load the saved R data I do not need to modify these options again. What is
>> the best way to do this? Is there a way without using an external file? I
>> tried save.image. However, only default setting is perserved.
>>
>
> You need to read about your options about setting options at startup. You
> can find information in the Installation Manual or by typing: ?Startup
>
> (I cannot think of a manner in which this can be tied to a data file being
> loaded.)
>
> --
>
> David Winsemius, MD
> West Hartford, CT
>
>

[[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] Question Using Old R Packages

2011-05-09 Thread c.hulmelowe
In case anyone else is having similar problems, it turns out it may have been
an issue with the interface I was using (R Studio). When I close R Studio
and tried it again through R it installed without the error message. 

Chris.

--
View this message in context: 
http://r.789695.n4.nabble.com/Question-Using-Old-R-Packages-tp3510721p3510726.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] Question Using Old R Packages

2011-05-09 Thread c.hulmelowe
I'm trying to use the package rgl for a research project. I've used it in the
past, but now when I try to re-install it after updating to R 2.13.0 I'm
getting the following error:

Warning in install.packages :
  package ‘rgl’ is not available (for R version 2.13.0)

Is there any way to get R to recognize this package, or am I going to have
to re-install an old version of R to use it?

Thanks in advance,

Chris.

--
View this message in context: 
http://r.789695.n4.nabble.com/Question-Using-Old-R-Packages-tp3510721p3510721.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] Reading a large netCDF file using R

2011-05-09 Thread sulochandhungel
I got a netCDF file from a climate group and wanted to aggregate the data.
The file summary looks like this

library(ncdf)
nc=open.ncdf("NCEP_prec_1949_58.nc")

> nc
[1] "file NCEP_prec_1949_58.nc has 4 dimensions:"
[1] "Time   Size: 14608"
[1] "lat   Size: 99"
[1] "lon   Size: 199"
[1] "DateStrLen   Size: 20"
[1] ""
[1] "file NCEP_prec_1949_58.nc has 1 variables:"
[1] "float Prec[lon,lat,Time]  Longname:yearly accumulated precip
Missval:1e+30"

I tried to get the variable values using this command

> xx=get.var.ncdf(nc)
Error: cannot allocate vector of size 2.1 Gb

This file has six hourly data for the 199 x 99 points for 10 years. I wanted
to aggregate this data into a monthly scale. I tried used a simple code like
this 

for (i in 1:noofdays) {
for (j in 0:3) {
x= get.var.ncdf(nc,v1,start=c(1,1,(i+j)),count=c(199,99,1))
temp_data_mat=temp_data_mat+x
}

for (x1 in 1:199) {
for (x2 in 1:99) {
data_mat_89_99[x1,x2,ctr]=temp_data_mat[x1,x2]
}
}
ctr=ctr+1
temp_data_mat=matrix(0,ncol=99,nrow=199)
}

I didnt think it worked... can u suggest me some other way ... I could not
use the start and count properly


--
View this message in context: 
http://r.789695.n4.nabble.com/Reading-a-large-netCDF-file-using-R-tp3510762p3510762.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] Creating Observation ID

2011-05-09 Thread Bill.Venables
Here is one way:

df <- data.frame(Value = rnorm(30),
 Group = sample(c('A','B','C'), 30,
 replace = TRUE))

## make a little function to do the job
iNumber <- function(f) {
  f <- as.factor(f)
  X <- outer(f, levels(f), "==")+0
  rowSums(X * apply(X, 2, cumsum))
}

## add the numbering column
df <- within(df, internalNumber <- iNumber(Group))

## Check that it works
> head(df)
   Value Group internalNumber
1 -1.5014788 C  1
2  0.6035679 C  2
3 -0.6953930 C  3
4 -0.2413863 A  1
5 -0.1170961 A  2
6  1.5110721 C  4 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Robert Baer
Sent: Tuesday, 10 May 2011 7:22 AM
To: R-help@r-project.org
Subject: [R] Creating Observation ID

If I have a data frame something like:
Value=rnorm(30)
Group = sample(c('A','B','C'), 30, replace=TRUE)
df = data.frame(Value, Group)

It seems like it should be simple to create an 'ObsID' column which indicates 
the observation order of each Value within each of the 3 groups.  Somehow, I 
can't quite see how to do it without manually sub-setting the parent data frame 
and then putting it back together again.  

Anyone able to get me started on a cleaner (more R-like) approach?

Thanks,

Rob

--
Robert W. Baer, Ph.D.
Professor of Physiology
Kirksville College of Osteopathic Medicine
A. T. Still University of Health Sciences
800 W. Jefferson St.
Kirksville, MO 63501
660-626-2322
FAX 660-626-2965

[[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] Lattice: splom plots for different factors with correlation in lower.panel

2011-05-09 Thread Tom Porteus
Hello list,
I am looking to create a figure for my dataset using splom, where there is a
splom subplot for each level of a factor within, for example, a 2x2 layout. 
For each subplot, I wish to put the r-value between each variable pair in
the lower panel.  The code I have thus far is below, using the iris dataset
so that it is reproducible.  This almost does what I want, but for some
reason overlays the r-values for each level in each subplot.

I think the problem is something to do with the lower.panel function call
within my custom function, but I am not a huge whizz using lattice and can't
figure out what it is.  If I put the panel.text call in the lower.panel
function, it only causes a similar problem.  Apologies if there is something
obvious I have missed, I hope there is someone out there who can help me!

var.cor <- list()
for(i in 1:3){
var.cor[[i]] <- abs(cor(subset(iris[1:4], iris$Species ==
levels(iris$Species)[i])))  #calculate variable correlation for each species
var.cor[[i]] <- data.frame(values = as.vector(var.cor[[i]]), row =
as.vector(row(var.cor[[i]])), col = as.vector(col(var.cor[[i]])))
var.cor[[i]] <- subset(var.cor[[i]], colhttp://r.789695.n4.nabble.com/Lattice-splom-plots-for-different-factors-with-correlation-in-lower-panel-tp3510452p3510452.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] Fortran Symbol Name not in Load Table

2011-05-09 Thread vioravis
I used the DLL export viewer to what is the table name being exported. It is
showing as VALUEAHROPTIMIZE_. This is the name of the function we have used
plus the underscore. 

Is there any other reason for the function not getting recognized??? Thanks.

--
View this message in context: 
http://r.789695.n4.nabble.com/Fortran-Symbol-Name-not-in-Load-Table-tp3509852p3510761.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] Filtering out bad data points

2011-05-09 Thread Bill.Venables
You could use a function to do the job:

withinRange <- function(x, r = quantile(x, c(0.05, 0.95)))
x >= r[1] & x <= r[2]

dtest2 <- subset(dftest, withinRange(x)) 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Robert A'gata
Sent: Tuesday, 10 May 2011 10:57 AM
To: r-help@r-project.org
Subject: [R] Filtering out bad data points

Hi,

I always have a question about how to do this best in R. I have a data
frame and a set of criteria to filter points out. My procedure is to
always locate indices of those points, check if index vector length is
greater than 0 or not and then remove them. Meaning

dftest <- data.frame(x=rnorm(100),y=rnorm(100));
qtile <- quantile(dftest$x,probs=c(0.05,0.95));
badIdx <- which((dftest$x < qtile[1]) | (dftest$x > qtile[2]));
if (length(badIdx) > 0) {
dftest <- dftest[-idx,];
}

My question is that is there a more streamlined way to achieve this? Thank you.

Cheers,

Robert

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

2011-05-09 Thread Robert A'gata
Hi,

I always have a question about how to do this best in R. I have a data
frame and a set of criteria to filter points out. My procedure is to
always locate indices of those points, check if index vector length is
greater than 0 or not and then remove them. Meaning

dftest <- data.frame(x=rnorm(100),y=rnorm(100));
qtile <- quantile(dftest$x,probs=c(0.05,0.95));
badIdx <- which((dftest$x < qtile[1]) | (dftest$x > qtile[2]));
if (length(badIdx) > 0) {
dftest <- dftest[-idx,];
}

My question is that is there a more streamlined way to achieve this? Thank you.

Cheers,

Robert

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


Re: [R] Stirlings Approximation

2011-05-09 Thread Kjetil Halvorsen
?lchoose
?lgamma
?lfactorial

On Mon, May 9, 2011 at 7:45 PM, Jim Silverton  wrote:
> I have some big combinations like:
>  choose 784645433
>
> Can R compute these?
> Is there any package that does stirlings approximation in R?
>
> --
> 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.
>

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


Re: [R] Stirlings Approximation

2011-05-09 Thread Jim Silverton
I have some big combinations like:
 choose 784645433

Can R compute these?
Is there any package that does stirlings approximation in R?

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


[R] Help with options("contrasts")

2011-05-09 Thread Axel Urbiz
Dear list,

Is it possible to specify a contrast in options() that would create an
identity matrix for each factor in the model matrix?
For example, for each factor in 'dd' below, I can create an identity matrix
using contrasts = FALSE. Is it possible to set this in options(), so when I
create a model matrix from any factor, the factor coding would follow this
specification for the contrast?

dd <- data.frame(a = gl(3,4), b = gl(4,1,12))
ca <- contrasts(dd$a, contrasts= FALSE)  # 3 x 3 identity matrix
cb <- contrasts(dd$b, contrasts= FALSE)  # 4 x 4 identity matrix
My attempt below works fine, but again, I'd like to specify this in the
options() as opposed to each contrast individually.
model.matrix(~ a + b, dd, contrasts =list(a=ca, b=cb))
Thanks for any help!
Axel.

[[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] Setting NA to blank

2011-05-09 Thread Dat Mai
I asked because I thought it'd solve an issue I had. I was actually being
quite rash in asking this question and for that, I apologize.

I wanted to know because I was attempting to create a heatmap where the NA
values would not be shown while all the outputs with actual numerical value
will be shown. I had assumed that setting the NA's to blanks would fix the
issue, but it hadn't. I refrained from immediately asking another question
so I that I can look further into this.

I hope that answers your question.

On Mon, May 9, 2011 at 4:21 PM, Ted Harding wrote:

> John Kane's reply sums it up! (Though you could use "",
> instead of " ", which would give you an "empty string"
> instead of the "space" character; but the resulting
> matrix would still consist entirely of "character"
> elements).
>
> However, the real reason I am following up is to ask
> why you want the blank instead of the NA.
>
> If it is just for printing out or display, then the
> fact that the matrix has been converted to character
> probably does not matter.
>
> But if it is for compatibility with some other
> computational software that (e.g.) expects missing
> values to be represented by a blank, or some "null"
> representation, then it may not be so straightforward.
>
> So, if that might be an issue, please describe for us
> how you intend to use the result.
>
> Ted.
>
> On 09-May-11 19:56:39, Dat Mai wrote:
> > Thank you kind sir!
> >
> > On Mon, May 9, 2011 at 3:25 PM, John Kane  wrote:
> >
> >>
> >> (mat <- matrix(c(1,2,3,NA),2))
> >> mat[is.na(mat)]   <- " "
> >> mat
> >>
> >> But if you have a numerical matrix it coverts the matrix to character.
> >>
> >> --- On Mon, 5/9/11, Dat Mai  wrote:
> >>
> >> > From: Dat Mai 
> >> > Subject: [R]  Setting NA to blank
> >> > To: r-help@r-project.org
> >> > Received: Monday, May 9, 2011, 2:46 PM
> >> > Hey All,
> >> >
> >> > I have a matrix m, and I wish to set all the NA values to
> >> > blank. How would I
> >> > do so?
> >> >
> >> > --
> >> > Best,
> >> > Dat Mai
> >> > PhD Rotation Student
> >> > Albert Einstein College of Medicine
>
> 
> E-Mail: (Ted Harding) 
> Fax-to-email: +44 (0)870 094 0861
> Date: 09-May-11   Time: 21:21:07
> -- XFMail --
>



-- 
Best,
Dat Mai
PhD Rotation Student
Albert Einstein College of Medicine

[[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] Creating Observation ID

2011-05-09 Thread William Dunlap
Does the following work for you?

 > df2 <- transform(df, ObsID=ave(rep(0,length(Group)), Group,
FUN=seq_along))
 > head(df2)
Value Group ObsID
 1 -0.0025132 B 1
 2 -1.2456156 A 1
 3 -2.0531704 B 2
 4  1.5861770 B 3
 5  0.1900908 A 2
 6  0.7197067 B 4

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 Robert Baer
> Sent: Monday, May 09, 2011 2:22 PM
> To: R-help@r-project.org
> Subject: [R] Creating Observation ID
> 
> If I have a data frame something like:
> Value=rnorm(30)
> Group = sample(c('A','B','C'), 30, replace=TRUE)
> df = data.frame(Value, Group)
> 
> It seems like it should be simple to create an 'ObsID' column 
> which indicates the observation order of each Value within 
> each of the 3 groups.  Somehow, I can't quite see how to do 
> it without manually sub-setting the parent data frame and 
> then putting it back together again.  
> 
> Anyone able to get me started on a cleaner (more R-like) approach?
> 
> Thanks,
> 
> Rob
> 
> --
> Robert W. Baer, Ph.D.
> Professor of Physiology
> Kirksville College of Osteopathic Medicine
> A. T. Still University of Health Sciences
> 800 W. Jefferson St.
> Kirksville, MO 63501
> 660-626-2322
> FAX 660-626-2965
> 
>   [[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] Creating Observation ID

2011-05-09 Thread Robert Baer
If I have a data frame something like:
Value=rnorm(30)
Group = sample(c('A','B','C'), 30, replace=TRUE)
df = data.frame(Value, Group)

It seems like it should be simple to create an 'ObsID' column which indicates 
the observation order of each Value within each of the 3 groups.  Somehow, I 
can't quite see how to do it without manually sub-setting the parent data frame 
and then putting it back together again.  

Anyone able to get me started on a cleaner (more R-like) approach?

Thanks,

Rob

--
Robert W. Baer, Ph.D.
Professor of Physiology
Kirksville College of Osteopathic Medicine
A. T. Still University of Health Sciences
800 W. Jefferson St.
Kirksville, MO 63501
660-626-2322
FAX 660-626-2965

[[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] interrupted time series analysis using ARIMA models

2011-05-09 Thread Roy Mendelssohn
Look at:

de Jong, P. and Penzer, J. (1998) Diagnosing shocks in time series. Journal of 
the American Statistical Association. 93, 796-806.

A pdf is available at:

http://stats.lse.ac.uk/penzer/publications.html

-Roy M.


On May 9, 2011, at 1:32 PM, jpehsani wrote:

> Hi Berta,
> 
> Did you have any luck finding code for the gradual permanent impact
> intervention? 
> 
> I am trying to fit two types of intervention effects for two different
> models - a gradual and a sudden impact effect - and unable to find any code
> on how to do this.
> thanks
> Jon 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/interrupted-time-series-analysis-using-ARIMA-models-tp794821p3510253.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.

**
"The contents of this message do not reflect any position of the U.S. 
Government or NOAA."
**
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
1352 Lighthouse Avenue
Pacific Grove, CA 93950-2097

e-mail: roy.mendelss...@noaa.gov (Note new e-mail address)
voice: (831)-648-9029
fax: (831)-648-8440
www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected"

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


Re: [R] maximum likelihood convergence reproducing Anderson Blundell 1982 Econometrica R vs Stata

2011-05-09 Thread Alex Olssen
Wow that is really interesting,

Sorry I was asleep when you emailed these.

And yes, of course, I had been trying to implement model 18, not 18s,
that was a typo, sorry.

I will have a look at the code you posted.

Thanks,

Alex

On 10 May 2011 02:18, peter dalgaard  wrote:
> Hmm, I tried replacing the x's in the model with their principal component 
> scores, and suddenly everything converges as a greased lightning:
>
>> Z <- princomp(cbind(x1,x2,x3))$scores
>> Z <- as.data.frame(princomp(cbind(x1,x2,x3))$scores)
>> names(Z)<- letters[1:3]
>> optimx(rep(0,8),lnl, hessian=TRUE, y1=y1, y2=y2,
> + x1=Z$a, x2=Z$b, x3=Z$c, method="BFGS")
>                                                                               
>                  par
> 1 0.59107682, 0.01043568, -0.20639153, 0.25902746, 0.24675162, -0.01426477, 
> 0.18045177, -0.23657327
>    fvalues method fns grs itns conv KKT1 KKT2 xtimes
> 1 -76.73878   BFGS 157  37 NULL    0 TRUE TRUE  0.055
> Warning messages:
> 1: In max(logpar) : no non-missing arguments to max; returning -Inf
> 2: In min(logpar) : no non-missing arguments to min; returning Inf
>
> The likelihood appears to be spot on, but, obviously, the parameter estimates 
> need to be back-transformed to the original x1,x2,x3 system. I'll leave that 
> as the proverbial "exercise for the reader"...
>
> However, the whole thing leads me to a suspicion that maybe our numerical 
> gradients are misbehaving in cases with high local collinearity?
>
> -pd
>
> On May 9, 2011, at 13:40 , Alex Olssen wrote:
>
>> Hi Mike,
>>
>> Mike said
>> "is this it, page 1559?"
>>
>> That is the front page yes, page 15*6*9 has the table, of which the
>> model labelled 18s is the one I replicated.
>>
>> "did you actually cut/paste code anywhere and is your first
>> coefficient -.19 or -.019?
>> Presumably typos would be one possible problem."
>>
>> -0.19 is not a typo, it is pi10 in the paper, and a1 in my Stata
>> estimation - as far as I can tell cutting and pasting is not the
>> problem.
>>
>> "generally it helps if we could at least see the equations to check your
>> code against typos ( note page number ?) in lnl that may fix part of the
>> mystery.  Is full text available
>> on author's site, doesn't come up on citeseer AFAICT,"
>>
>> Unfortunately I do not know of any place to get the full version of
>> this paper that doesn't require access to a database such as JSTOR.
>> The fact that this likelihood function reproduces the published
>> results in Stata makes me confident that it is correct - I also have
>> read a lot on systems estimation and it is a pretty standard
>> likelihood function.
>>
>> "I guess one question would be " what is beta" in lnl supposed to be -
>> it isn't used anywhere but I will also mentioned I'm not that familiar
>> with the R code ( I'm trying to work through this to learn R and the
>> optimizers).
>>
>> maybe some words would help, is sigma supposed to be 2x2 or 8x8 and what are
>> e1 and e2 supposed to be?"
>>
>> The code above is certainly not as elegant as it could be - in this
>> case the beta is rather superfluous.  It is just a vector to hold
>> parameters - but since I called all the parameters theta anyway there
>> is no need for it.  e1 and e2 are the residuals from the first and
>> second equations of the system.  Sigma is a 2x2 matrix which is the
>> outer product of the two vectors of residuals.
>>
>> Kind regards,
>>
>> Alex
>>
>>
>>
>> On 9 May 2011 23:12, Mike Marchywka  wrote:
>>>
>>>
>>>
>>>
>>>
>>>
>>> 
 Date: Mon, 9 May 2011 22:06:38 +1200
 From: alex.ols...@gmail.com
 To: pda...@gmail.com
 CC: r-help@r-project.org; da...@otter-rsch.com
 Subject: Re: [R] maximum likelihood convergence reproducing Anderson 
 Blundell 1982 Econometrica R vs Stata

 Peter said

 "Ahem! You might get us interested in your problem, but not to the
 level that we are going to install Stata and Tsp and actually dig out
 and study the scientific paper you are talking about. Please cite the
 results and explain the differences."

 Apologies Peter, will do,

 The results which I can emulate in Stata but not (yet) in R are reported 
 below.
>>>
>>> did you actually cut/paste code anywhere and is your first coefficient -.19 
>>> or -.019?
>>> Presumably typos would be one possible problem.
>>>
 They come from Econometrica Vol. 50, No. 6 (Nov., 1982), pp. 1569
>>>
>>>
>>> is this it, page 1559?
>>>
>>> http://www.jstor.org/pss/1913396
>>>
>>> generally it helps if we could at least see the equations to check your
>>> code against typos ( note page number ?) in lnl that may fix part of the
>>> mystery.  Is full text available
>>> on author's site, doesn't come up on citeseer AFAICT,
>>>
>>>
>>> http://citeseerx.ist.psu.edu/search?q=blundell+1982&sort=ascdate
>>>
>>> I guess one question would be " what is beta" in lnl supposed to be -
>>> it isn't used anywhere but I will also m

Re: [R] interrupted time series analysis using ARIMA models

2011-05-09 Thread jpehsani
Hi Berta,

Did you have any luck finding code for the gradual permanent impact
intervention? 

I am trying to fit two types of intervention effects for two different
models - a gradual and a sudden impact effect - and unable to find any code
on how to do this.
thanks
Jon 

--
View this message in context: 
http://r.789695.n4.nabble.com/interrupted-time-series-analysis-using-ARIMA-models-tp794821p3510253.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] Averaging uneven measurements by time with uneven numbers of measurements

2011-05-09 Thread Adele_Thompson
An easy way to average every 30 minutes is using the aggregate function. First 
I use the mod (%%) to get times as the next earliest possible 30 min time 
increment. 

bTime<-  as.POSIXct(c( "2011-04-28 09:02:00 CDT","2011-04-28 09:02:00 
CDT","2011-04-28 09:12:00 CDT","2011-04-28 09:14:00 CDT","2011-04-28 09:15:00 
CDT","2011-04-28 09:23:00 CDT","2011-04-28 09:45:00 CDT","2011-04-28 09:53:00 
CDT","2011-04-28 10:03:00 CDT"))
numTime<-as.numeric(bTime)-21600
Weight<-runif(9)*100
minT<-30
excess<-numTime %% (minT*60)
nTime<-numTime-excess
nDateT<-as.POSIXct(nTime, origin="1970-01-01",tz= "US/Central")
meanw <- aggregate(Weight, list(nDateT), mean, na.rm = TRUE)



-Original Message-
From: cl...@ecy.wa.gov [mailto:cl...@ecy.wa.gov] 
Sent: Thursday, May 05, 2011 03:58 PM
To: Thompson, Adele - adele_thomp...@cargill.com
Cc: r-help@r-project.org
Subject: Re: [R] Averaging uneven measurements by time with uneven numbers of 
measurements

In your first request for help you said, "How do I average the 
measurements by every 30 minutes?"  With 25000 readings over three 
days, it looks as if you are getting readings just about every 
second.

Okay, why don't you use the first reading as your initial weight, 
w0.  Then subtract each succeeding reading from that to obtain the 
amount of feed dispensed.  Now plot that value every 30 minutes.

If you are interested in the variation of feed dispensed over a 
half hour interval, that can be easily obtained by accummulating 
those half-hour readings.

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


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


On Thu, 5 May 2011, Schatzi wrote:

> I do not want smoothing as the data should have jumps (it is weight left in
> feeding bunker). I was thinking of maybe using a histogram-like function and
> then averaging that. Not sure if this is possible.
>
> -
> In theory, practice and theory are the same. In practice, they are not - 
> Albert Einstein
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Averaging-uneven-measurements-by-time-with-uneven-numbers-of-measurements-tp3499337p3499386.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] Setting NA to blank

2011-05-09 Thread Ted Harding
John Kane's reply sums it up! (Though you could use "",
instead of " ", which would give you an "empty string"
instead of the "space" character; but the resulting
matrix would still consist entirely of "character"
elements).

However, the real reason I am following up is to ask
why you want the blank instead of the NA.

If it is just for printing out or display, then the
fact that the matrix has been converted to character
probably does not matter.

But if it is for compatibility with some other
computational software that (e.g.) expects missing
values to be represented by a blank, or some "null"
representation, then it may not be so straightforward.

So, if that might be an issue, please describe for us
how you intend to use the result.

Ted.

On 09-May-11 19:56:39, Dat Mai wrote:
> Thank you kind sir!
> 
> On Mon, May 9, 2011 at 3:25 PM, John Kane  wrote:
> 
>>
>> (mat <- matrix(c(1,2,3,NA),2))
>> mat[is.na(mat)]   <- " "
>> mat
>>
>> But if you have a numerical matrix it coverts the matrix to character.
>>
>> --- On Mon, 5/9/11, Dat Mai  wrote:
>>
>> > From: Dat Mai 
>> > Subject: [R]  Setting NA to blank
>> > To: r-help@r-project.org
>> > Received: Monday, May 9, 2011, 2:46 PM
>> > Hey All,
>> >
>> > I have a matrix m, and I wish to set all the NA values to
>> > blank. How would I
>> > do so?
>> >
>> > --
>> > Best,
>> > Dat Mai
>> > PhD Rotation Student
>> > Albert Einstein College of Medicine


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 09-May-11   Time: 21:21:07
-- 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] Create subsets of data

2011-05-09 Thread David Winsemius


On May 9, 2011, at 3:46 PM, David Winsemius wrote:



On May 9, 2011, at 9:40 AM, Pavan G wrote:


Hello All,
Let's say I have points on a x-y plane. x ranges from 0-2 and y  
from 0-2.
There are points in quadrants x[0:1]---y[0:1] and in x[1:2] 
y[1:2]. I
would like to get the mean and std of the points in the x[0:1] 
y[0:1]

quadrant alone. Is there a straight forward way to do it?


I am assuming that you have yet a third vector that has values at  
each of those coordinates and it is that set of categorized values  
for which you want the means and std deviations: I will exemplify  
the use of tapply on cut()-igorized vectors and a z-value which is  
the L1 distance from the origin.


(Actually, after checking help(dist)  I think the sum(x_i) is called  
the Canberra distance. )



(And excuse the earlier feeble attempt at humor);

> x <- runif(2000, 0,2)
> y <- runif(2000, 0, 2)
> xc <- cut(x, c(0,1,2))
> yc <- cut(y, c(0,1,2))
> z <- x+y
> tapply(z, list(xc,yc), mean)
(0,1](1,2]
(0,1] 1.013192 2.016095
(1,2] 1.979930 2.996229  # seems to make sense
> tapply(z, list(xc,yc), sd)
 (0,1] (1,2]
(0,1] 0.4028310 0.4133113
(1,2] 0.4239014 0.3984559 # also seems sensible
--




David Winsemius, MD
West Hartford, CT

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


Re: [R] Setting NA to blank

2011-05-09 Thread Dat Mai
Thank you kind sir!

On Mon, May 9, 2011 at 3:25 PM, John Kane  wrote:

>
> (mat <- matrix(c(1,2,3,NA),2))
> mat[is.na(mat)]   <- " "
> mat
>
> But if you have a numerical matrix it coverts the matrix to character.
>
> --- On Mon, 5/9/11, Dat Mai  wrote:
>
> > From: Dat Mai 
> > Subject: [R]  Setting NA to blank
> > To: r-help@r-project.org
> > Received: Monday, May 9, 2011, 2:46 PM
> > Hey All,
> >
> > I have a matrix m, and I wish to set all the NA values to
> > blank. How would I
> > do so?
> >
> > --
> > Best,
> > Dat Mai
> > PhD Rotation Student
> > Albert Einstein College of Medicine
>
>


-- 
Best,
Dat Mai
PhD Rotation Student
Albert Einstein College of Medicine

[[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] Create subsets of data

2011-05-09 Thread David Winsemius


On May 9, 2011, at 9:40 AM, Pavan G wrote:


Hello All,
Let's say I have points on a x-y plane. x ranges from 0-2 and y from  
0-2.
There are points in quadrants x[0:1]---y[0:1] and in x[1:2] 
y[1:2]. I
would like to get the mean and std of the points in the x[0:1] 
y[0:1]

quadrant alone. Is there a straight forward way to do it?


I am assuming that you have yet a third vector that has values at each  
of those coordinates and it is that set of categorized values for  
which you want the means and std deviations: I will exemplify the use  
of tapply on cut()-igorized vectors and a z-value which is the L1  
distance from the origin. (And excuse the earlier feeble attempt at  
humor);


> x <- runif(2000, 0,2)
> y <- runif(2000, 0, 2)
> xc <- cut(x, c(0,1,2))
> yc <- cut(y, c(0,1,2))
> z <- x+y
> tapply(z, list(xc,yc), mean)
 (0,1](1,2]
(0,1] 1.013192 2.016095
(1,2] 1.979930 2.996229  # seems to make sense
> tapply(z, list(xc,yc), sd)
  (0,1] (1,2]
(0,1] 0.4028310 0.4133113
(1,2] 0.4239014 0.3984559 # also seems sensible





--

David Winsemius, MD
West Hartford, CT

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


Re: [R] Using NULL to my data?

2011-05-09 Thread Nilza BARROS
Dear Gabor,

Thanks for your help. I was trying to do what you ask me and I've found the
solution.

> with(teste,sprintf("INSERT INTO OBS (date,T_2M,TMAX_2M,TMIN_2M) VALUES
(%s, %5.2f, %5.2f, %5.2f,%s)",date2,T_2M,TMAX_2M,TMIN_2M,Station_NO))
Error in sprintf("INSERT INTO OBS (date,T_2M,TMAX_2M,TMIN_2M) VALUES (%s,
%5.2f, %5.2f, %5.2f,%s)",  :
  invalid format '%5.2f'; use format %s for character objects
>
>
> with(teste,sprintf("INSERT INTO OBS (date,T_2M,TMAX_2M,TMIN_2M) VALUES
(%s, %s, %s, %s,%s)",date2,T_2M,TMAX_2M,TMIN_2M,Station_NO))

 [1] "INSERT INTO OBS (date,T_2M,TMAX_2M,TMIN_2M) VALUES (2011042912, 22.5,
NULL, 22.4,820420)"
 [2] "INSERT INTO OBS (date,T_2M,TMAX_2M,TMIN_2M) VALUES (2011042912, 26.9,
NULL, 23.4,820980)"
 [3] "INSERT INTO OBS (date,T_2M,TMAX_2M,TMIN_2M) VALUES (2011042912, 24.3,
NULL, 23.3,821130)"
 [4] "INSERT INTO OBS (date,T_2M,TMAX_2M,TMIN_2M) VALUES (2011042912, 24.4,
NULL, 23.7,821410)"
 [5] "INSERT INTO OBS (date,T_2M,TMAX_2M,TMIN_2M) VALUES (2011042912, 28.2,
NULL, 21.1,821450)"
 [6] "INSERT INTO OBS (date,T_2M,TMAX_2M,TMIN_2M) VALUES (2011042912, 23.3,
NULL, 22.8,821810)"


On Mon, May 9, 2011 at 2:05 PM, Gabor Grothendieck
wrote:

>  On Mon, May 9, 2011 at 12:59 PM, Nilza BARROS 
> wrote:
> > Hi, Thanks for your attentio.
> >
> > I have the data frame below:
> > 
> >> head(Alldados)
> >   Station_NO   date1 T_2M TMAX_2M TMIN_2M TD_2M PS FF_10M DD_10M
> > 1 820420 110429/1200 22.5NULL22.4  22.2   NULL  0  0
> > 2 820980 110429/1200 26.9NULL23.4  24.1 1010.2   2.91360
> > 3 821130 110429/1200 24.3NULL23.3  23.7   NULL   1.94230
> > 4 821410 110429/1200 24.4NULL23.7  24.2 1011.8   2.91270
> > 5 821450 110429/1200 28.2NULL21.1  25.8 1008.8  0  0
> > 6 821810 110429/1200 23.3NULL22.8  22.9 1001.6  0  0
> >   TOT_PRCP CLCL  date2
> > 184.00 NULL 2011042912
> > 2 2.00 NULL 2011042912
> > 3 3.00 NULL 2011042912
> > 412.00 NULL 2011042912
> > 5 6.00 NULL 2011042912
> > 638.00 NULL 2011042912
> > 
> > Now each line will feed my database. So I need to format each line like
> > below:
> >
> > ===
> >  [1] "INSERT INTO OBS
> >
> (date,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO)
> > VALUES (2011042912, 22.50,NA, 22.40,22.20,   NA, 0.00, 0.00,36.00,
> > NA,820420)"
> >   [2] "INSERT INTO OBS
> >
> (date,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO)
> > VALUES (2011042912, 26.90,NA, 23.40,24.10,1010.20, 2.91,360.00,16.00,
> > NA,820980)"
> >   [3] "INSERT INTO OBS
> >
> (date,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO)
> > VALUES (2011042912, 24.30,NA, 23.30,23.70,   NA, 1.94,230.00,19.00,
> > NA,821130)"
> >   [4] "INSERT INTO OBS
> >
> (date,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO)
> > VALUES (2011042912, 24.40,NA, 23.70,24.20,1011.80, 2.91,270.00,12.00,
> > NA,821410)"
> >   [5] "INSERT INTO OBS
> >
> (date,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO)
> > VALUES (2011042912, 28.20,NA, 21.10,25.80,1008.80, 0.00, 0.00,31.00,
> > NA,821450)"
> >   [6] "INSERT INTO OBS
> >
> (date,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO)
> > VALUES (2011042912, 23.30,NA, 22.80,22.90,1001.60, 0.00, 0.00,24.00,
> > NA,821810)"
> >   [7] "INSERT INTO OBS
> > ===
> >
>
> Please
>
> 1. reduce Allados to a smaller number of columns and rows.  Say 10
> rows and 3 columns such that it still exhibits the problem and then
> show the result of dput:
>
> dput(smallDF)
>
> 2. provide the R code that you would use with smallDF
>
> 3. explain what the problem is and how that differs from what you expect.
>
> --
>  Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
>



-- 
Abraço,
Nilza Barros

[[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] Setting NA to blank

2011-05-09 Thread John Kane

(mat <- matrix(c(1,2,3,NA),2))
mat[is.na(mat)]   <- " "
mat

But if you have a numerical matrix it coverts the matrix to character.

--- On Mon, 5/9/11, Dat Mai  wrote:

> From: Dat Mai 
> Subject: [R]  Setting NA to blank
> To: r-help@r-project.org
> Received: Monday, May 9, 2011, 2:46 PM
> Hey All,
> 
> I have a matrix m, and I wish to set all the NA values to
> blank. How would I
> do so?
> 
> -- 
> Best,
> Dat Mai
> PhD Rotation Student
> Albert Einstein College of Medicine

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


Re: [R] Create subsets of data

2011-05-09 Thread Steve Lianoglou
Hi,

On Mon, May 9, 2011 at 9:40 AM, Pavan G  wrote:
> Hello All,
> Let's say I have points on a x-y plane. x ranges from 0-2 and y from 0-2.
> There are points in quadrants x[0:1]---y[0:1] and in x[1:2]y[1:2]. I
> would like to get the mean and std of the points in the x[0:1]y[0:1]
> quadrant alone. Is there a straight forward way to do it?
>
> I asked a similar question a few days ago regarding plotting a subset of
> data using conditions. The solution was:
> http://r.789695.n4.nabble.com/Conditional-plot-length-in-R-td3503855.html

The solution to this question will also be similar, I guess ... you
should take some time to figure out how indexing with (different types
of) vectors works:

http://cran.r-project.org/doc/manuals/R-intro.html#Index-vectors

If your question doesn't have to do with selecting the appropriate
elements of your data, are you asking how to take a "mean" or std.dev
of the subset of points you know how to select? It's not clear what
you mean by "mean" ... do you want the average value of x vs. avg.
value of y ... or do you want the "centroid" of a set of points in
each quadrant, or ... what?

> Thank you,
> Why-so-serious.

A curious choice for a valediction ...

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

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

2011-05-09 Thread Dat Mai
All right then--I shall get bash away. Thanks a lot.

On Mon, May 9, 2011 at 2:55 PM, Deepayan Sarkar
wrote:

> On Mon, May 9, 2011 at 8:23 PM, Dat Mai  wrote:
> > Thanks for the help! Though, when I do this, I get a message saying
> "Error
> > using packet 1 value where TRUE/FALSE." Would that have anything to do
> with
> > this set of code?
>
> It might. (As we don't know what you "did", we can't really say.)
>
> > On Sun, May 8, 2011 at 3:00 PM, Deepayan Sarkar <
> deepayan.sar...@gmail.com>
> > wrote:
> >>
> >> On Fri, May 6, 2011 at 10:21 PM, Dat Mai  wrote:
> >> > Hello all,
> >> >
> >> > I'm trying  to create a heatmap using 2 matrices I have: z and v. Both
> >> > matrices represent different correlations for the same independent
> >> > variables. The problem I have is that I wish to have the values from
> >> > matrix
> >> > z to be represented by color intensity while having the values from
> >> > matrix v
> >> > to be represented by circle size. I currently have the following in
> >> > front of
> >> > me and an unsure of what to add or change in order to achieve that
> goal.
> >> >
> >> > panel.corrgram.2 =
> >> > function(x, y, z, subscripts, at = pretty(z), scale = 0.8, ...)
> >> > {
> >> >  require("grid", quietly = TRUE)
> >> >  x <- as.numeric(x)[subscripts]
> >> >  y <- as.numeric(y)[subscripts]
> >> >  z <- as.numeric(z)[subscripts]
> >> >  zcol <- level.colors(z, at = at, ...)
> >> >  for (i in seq(along = z))
> >> >  {
> >> >lims <- range(0, z[i])
> >> >tval <- 2 * base::pi * seq(from = lims[1], to = lims[2], by = 0.01)
> >> >grid.polygon(x = x[i] + .5 * scale * c(0, sin(tval)),
> >> >  y = y[i] + .5 * scale * c(0, cos(tval)),
> >> >  default.units = "native",
> >> >  gp = gpar(fill = zcol[i]))
> >> >grid.circle(x = x[i], y = y[i], r = .5 * scale,
> >> >  default.units = "native")
> >> >  }
> >> > }
> >>
> >> Probably this modification
> >>
> >> panel.corrgram.2 <-
> >>function(x, y, z, v, subscripts, at = pretty(v), scale = 0.8, ...)
> >> {
> >>require("grid", quietly = TRUE)
> >>x <- as.numeric(x)[subscripts]
> >>y <- as.numeric(y)[subscripts]
> >>z <- as.numeric(z)[subscripts]
> >>zcol <- level.colors(v, at = at, ...)
> >>
> >>
> >>
> >>
> >> followed by
> >>
> >> levelplot(signif(z,3), v = v, panel = panel.corrgram.2, ...)
> >>
> >> will do it.
> >>
> >> -Deepayan
> >>
> >>
> >> >
> >> > k=levelplot(signif(z,3), scales = list(x = list(rot = 45)),
> >> > col.regions=col.sch, panel = panel.corrgram.2,
> >> > label = num.circ, xlab="", ylab="", main=paste(output,"receptor
> >> > response"))
> >> > print(k)
> >> >
> >> > --
> >> > Best,
> >> > Dat Mai
> >> > PhD Rotation Student
> >> > Albert Einstein College of Medicine
> >> >
> >> >[[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.
>



-- 
Best,
Dat Mai
PhD Rotation Student
Albert Einstein College of Medicine

[[alternative HTML version deleted]]

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


Re: [R] How to alter circle size

2011-05-09 Thread Deepayan Sarkar
On Mon, May 9, 2011 at 8:23 PM, Dat Mai  wrote:
> Thanks for the help! Though, when I do this, I get a message saying "Error
> using packet 1 value where TRUE/FALSE." Would that have anything to do with
> this set of code?

It might. (As we don't know what you "did", we can't really say.)

> On Sun, May 8, 2011 at 3:00 PM, Deepayan Sarkar 
> wrote:
>>
>> On Fri, May 6, 2011 at 10:21 PM, Dat Mai  wrote:
>> > Hello all,
>> >
>> > I'm trying  to create a heatmap using 2 matrices I have: z and v. Both
>> > matrices represent different correlations for the same independent
>> > variables. The problem I have is that I wish to have the values from
>> > matrix
>> > z to be represented by color intensity while having the values from
>> > matrix v
>> > to be represented by circle size. I currently have the following in
>> > front of
>> > me and an unsure of what to add or change in order to achieve that goal.
>> >
>> > panel.corrgram.2 =
>> > function(x, y, z, subscripts, at = pretty(z), scale = 0.8, ...)
>> > {
>> >  require("grid", quietly = TRUE)
>> >  x <- as.numeric(x)[subscripts]
>> >  y <- as.numeric(y)[subscripts]
>> >  z <- as.numeric(z)[subscripts]
>> >  zcol <- level.colors(z, at = at, ...)
>> >  for (i in seq(along = z))
>> >  {
>> >    lims <- range(0, z[i])
>> >    tval <- 2 * base::pi * seq(from = lims[1], to = lims[2], by = 0.01)
>> >    grid.polygon(x = x[i] + .5 * scale * c(0, sin(tval)),
>> >      y = y[i] + .5 * scale * c(0, cos(tval)),
>> >      default.units = "native",
>> >      gp = gpar(fill = zcol[i]))
>> >    grid.circle(x = x[i], y = y[i], r = .5 * scale,
>> >      default.units = "native")
>> >  }
>> > }
>>
>> Probably this modification
>>
>> panel.corrgram.2 <-
>>    function(x, y, z, v, subscripts, at = pretty(v), scale = 0.8, ...)
>> {
>>    require("grid", quietly = TRUE)
>>    x <- as.numeric(x)[subscripts]
>>    y <- as.numeric(y)[subscripts]
>>    z <- as.numeric(z)[subscripts]
>>    zcol <- level.colors(v, at = at, ...)
>>
>>    
>>
>>
>> followed by
>>
>> levelplot(signif(z,3), v = v, panel = panel.corrgram.2, ...)
>>
>> will do it.
>>
>> -Deepayan
>>
>>
>> >
>> > k=levelplot(signif(z,3), scales = list(x = list(rot = 45)),
>> > col.regions=col.sch, panel = panel.corrgram.2,
>> > label = num.circ, xlab="", ylab="", main=paste(output,"receptor
>> > response"))
>> > print(k)
>> >
>> > --
>> > Best,
>> > Dat Mai
>> > PhD Rotation Student
>> > Albert Einstein College of Medicine
>> >
>> >        [[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] Setting NA to blank

2011-05-09 Thread Dat Mai
Hey All,

I have a matrix m, and I wish to set all the NA values to blank. How would I
do so?

-- 
Best,
Dat Mai
PhD Rotation Student
Albert Einstein College of Medicine

[[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] Vectorizing a function: what does it mean?

2011-05-09 Thread Duncan Murdoch

On 09/05/2011 11:57 AM, Ron Michael wrote:

Dear all, I would really appreciate if somebody can help me to understand what does the 
phrase "Vectorize your function" mean? And what is the job of Vectorize() 
function in doing that? I have read many threads where experts suggest to Vectorize the 
function, which will speed up entire calculation (and more elegant ofcourse.)

I used to think that vectorizing function means, to create a function such a 
way so that if input(s) are vector then this function will also return a vector 
output (without having any extra effort like use of 'for' loop etc.) Is this 
understanding correct?


That's correct.

Here I have tried 2 essentially similar functions:

>  fn1<- function(x,y,z) return(x+y+z)
>  fn2<- Vectorize(function(x,y,z) return(x+y+z), SIMPLIFY=TRUE)
>  fn1(1:3, 4:6,5)
[1] 10 12 14
>  fn2(1:3, 4:6,5)
[1] 10 12 14


You see that, fn1() and fn2() is giving same answer (vectorized?) despite of 
the fact that fn1() is not wrapped within Vectorize() function. Therefore I 
want to know: what additional thing this Vectorize() function brings on the 
table?


Addition is already vectorized, so Vectorize does nothing but slow down 
your function. In other cases it is more helpful.  For example, if you 
wanted to compute the residual sum of squares from fitting a mean to a 
vector of data, you might write


y <- rnorm(100)  # some fake data
RSS <- function(mu) sum( (y-mu)^2 )

That works only if mu is a scalar, but Vectorize(RSS) would work for a 
vector of mu values.


Duncan Murdoch

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


Re: [R] Vectorizing a function: what does it mean?

2011-05-09 Thread Duncan Murdoch

On 09/05/2011 1:31 PM, David Winsemius wrote:

On May 9, 2011, at 11:57 AM, Ron Michael wrote:

>  Dear all, I would really appreciate if somebody can help me to
>  understand what does the phrase "Vectorize your function" mean? And
>  what is the job of Vectorize() function in doing that? I have read
>  many threads where experts suggest to Vectorize the function, which
>  will speed up entire calculation (and more elegant ofcourse.)
>
>  I used to think that vectorizing function means, to create a
>  function such a way so that if input(s) are vector then this
>  function will also return a vector output (without having any extra
>  effort like use of 'for' loop etc.) Is this understanding correct?
>
>  Here I have tried 2 essentially similar functions:
>
>>  fn1<- function(x,y,z) return(x+y+z)
>>  fn2<- Vectorize(function(x,y,z) return(x+y+z), SIMPLIFY=TRUE)
>>  fn1(1:3, 4:6,5)
>  [1] 10 12 14
>>  fn2(1:3, 4:6,5)
>  [1] 10 12 14
>
>
>  You see that, fn1() and fn2() is giving same answer (vectorized?)
>  despite of the fact that fn1() is not wrapped within Vectorize()
>  function. Therefore I want to know: what additional thing this
>  Vectorize() function brings on the table?

That is because you used "+"  which is "vectorized" to start with. Try
is with "sum" and you will not be as "happy"
  >  sum(a=1:3, b=4:6, cc=7:9)
[1] 45

It removed all your structure.

  >  Vsum<-function(...) {what<- list(...); lenlist<- length(what);
y<-matrix(unlist(what), ncol=lenlist); apply(y,1,sum)}
  >  Vsum(a=1:3, b=4:6, cc=7:9)
[1] 12 15 18
# Does not recycle as I might have expected, although it does recycle
  >  (Vsum( a=1:3, b=4:6, cc=7))
[1] 12  8 11


  >  (mapply(sum, a=1:3, b=4:6, cc=7:9))
   # also works and recycles as expected:
[1] 12 15 18

  >  (mapply(sum, a=1:3, b=4:6, cc=7))
[1] 12 14 16

# but _not_ VSum<- Vectorize(sum) for reasons not clear to me behaves
the same as sum()


The problem with Vectorize(sum) is that Vectorize doesn`t see any 
parameters to vectorize in sum().  It needs simple functions with 
parameters like fn1, and it rewrites them to loop over the values of the 
parameters.


Duncan Murdoch

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


[R] Approximate name matching

2011-05-09 Thread Stavros Macrakis
Is there R software available for doing approximate matching of personal
names?

I have data about the same people produced by different organizations and
the only matching key I have is the name. I know that commercial solutions
exist, and I know I code code this from scratch, but I'd prefer to build on
some existing free solution if it exists.

Unfortunately, the names are not standardized, and there is also a certain
level of error:

   Danny Williams (nickname)
   Dan Williams (nickname)
   Daniel Williams (nickname)
   Dan William (spelling error)
   D. Williams (initials)
   Daniel "Danny" Williams (formal + nickname)
   Dan P. Williams (includes middle initial)
   Williams, Daniel (different convention)
   William Daniel (wrong order or missing comma + misspelling)

Is there any R software available to find likely matches, ideally with some
estimate of accuracy of match?  Levenshtein distance as implemented in agrep
is a useful solution for some of these cases; I was wondering if there is
something that covers more cases.

For this particular application, I am not concerned with issues such as
variant latinizations/transliterations (e.g. Tsung-Dao Lee ~ T.D. Lee ~ Li
Zhengdao; Ghaddafi ~ Qaddhaffi), but of course if someone handles that as
well

Thanks,

-s

[[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] Round down to earliest hour or half hour

2011-05-09 Thread Jeff Newmiller
One way, assuming your timestamps are POSIXct format:

truncInterval <- function ( x, dx=as.difftime(1,units="days") ) {
xn <- as.numeric( x )
result <- xn - xn %% as.numeric( dx, units="secs" )
class( result ) <- 'POSIXct'
result
}

truncInterval( as.POSIXct(c("2011-04-28 09:20:00", "2011-04-28 09:40:00")), 
as.difftime(30,units="mins") )

This may not work well if the timestamp granularity is more fine than one 
second.
---
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.

Schatzi  wrote:

I have times and would like to round down to the earliest 30 minute increment. 
For instance, a time of 2011-04-28 09:02:00 (the as.numeric value = 1303999320) 
I would like it to be rounded down to: 2011-04-28 09:00:00 (the as.numeric 
value = 1303999200) Any ideas of how to do this? - In theory, practice and 
theory are the same. In practice, they are not - Albert Einstein -- View this 
message in context: 
http://r.789695.n4.nabble.com/Round-down-to-earliest-hour-or-half-hour-tp3509374p3509374.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] Time Series

2011-05-09 Thread Gabor Grothendieck
On Mon, May 9, 2011 at 10:20 AM, Nicole Gross-Camp
 wrote:
> I have what I hope is a simple question - is it possible to do time series
> analysis on a small data set specifically only four data points?
>
>
>
> I have collected human threat data (mean number of threats per kilometre
> walked/ survey) every 3 months in eight different sites (four with an
> experimental element and four control sites). I am trying to determine the
> best way to determine if there is a trend in the data though from what I've
> seen of TSA, our data set is too small. I did a simple paired t-test on the
> first and average of following three surveys that shows no significant
> difference but it of course ignores the detail of the latter three surveys.
>
>
>
> I am not sure how to organize the data for importation into R. I've looked
> at Crawley and one of Zuur publications but the TS data they work with is
> much longer term and not over several (independent) sites.
>
>
>
> Any advice, help, or direction is much appreciated!
>

This i panel data where you have 8 time series, not one time series,
right?   You could try a gls model with an AR1 correlation error
structure for each of the 8 series.   See the analysis of the Owl data
set in Zuur.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at 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] arima residuals

2011-05-09 Thread Luis Solis
Hi

I have fitted an arima model to a monthly series of length 113.

I have use

fit <- arima(x.ts, order = c(1,0,0),seas = list(order = c(1,2,1),12, method
= "CSS")

I'm a little confused because the series of residual has the first 46 values
equal to 0. From there the residuals are approximately while noise, numbers
have a mean close to 0 and a variance value.

What could be causing these results?

-- 
Luis

[[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] Fortran Symbol Name not in Load Table

2011-05-09 Thread vioravis
I am trying to call a FORTRAN subroutine from R. is.loaded is turning out to
be TRUE. However when I run my .Fortran command I get the following error: 

Error in .Fortran("VALUEAHROPTIMIZE", as.double(ahrArray),
as.double(kwArray),  : 
  Fortran symbol name "valueahroptimize" not in load table 


I have given the FORTRAN declaration below: 

subroutine VALUEAHROPTIMIZE(AHR,& 
KW,& 
min_IHR_delta,  & 
max_AHR_error,  & 
AHR_out,   & !! Output AHE array 
IHR_out,   & !! Output IHR array 
Errors_out) 
  ! Expose subroutine my_function to users of this DLL 
  !DEC$ ATTRIBUTES
DLLEXPORT,C,REFERENCE,ALIAS:'VALUEAHROPTIMIZE_'::VALUEAHROPTIMIZE 
  
  ! Body of my_function 
  
  Implicit None 
  
  Integer *4  IERR, iSum 
  DOUBLE PRECISION min_IHR_delta, max_AHR_error 
  logical switch_AHR_tuner 
  character * 512 AHR_tuner_FilePath 
  
  !!DOUBLE PRECISION  AHR(500), kW(500)  !! Initial Array for reading
Namelist 
  
  DOUBLE PRECISION  AHR(*), kW(*)  !! Initial Array for reading Namelist 
  DOUBLE PRECISION  AHR_out(*), IHR_out(*) 
  integer Errors_out(*) 


The R code I tried using is given below: 

ahrArray <- runif(147) 
kwArray <- runif(147) 
outputAHR <- c(rep(0,11*11)) 
outputIHR <- c(rep(0,11*11)) 
outputError <- c(rep(NA,11)) 

dyn.load("my_function.dll") 
is.loaded("VALUEAHROPTIMIZE") 

[1] TRUE 

> .Fortran("VALUEAHROPTIMIZE", 
  as.double(ahrArray), 
  as.double(kwArray), 
  as.double(0.0005), 
  as.double(5), 
  as.double(outputAHR), 
  as.double(outputIHR), 
  as.integer(outputError)) 

Can someone please help me with how to fix this issue? Thank you. 

Ravi  



--
View this message in context: 
http://r.789695.n4.nabble.com/Fortran-Symbol-Name-not-in-Load-Table-tp3509852p3509852.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] Vectorizing a function: what does it mean?

2011-05-09 Thread David Winsemius


On May 9, 2011, at 11:57 AM, Ron Michael wrote:

Dear all, I would really appreciate if somebody can help me to  
understand what does the phrase "Vectorize your function" mean? And  
what is the job of Vectorize() function in doing that? I have read  
many threads where experts suggest to Vectorize the function, which  
will speed up entire calculation (and more elegant ofcourse.)


I used to think that vectorizing function means, to create a  
function such a way so that if input(s) are vector then this  
function will also return a vector output (without having any extra  
effort like use of 'for' loop etc.) Is this understanding correct?


Here I have tried 2 essentially similar functions:


fn1 <- function(x,y,z) return(x+y+z)
fn2 <- Vectorize(function(x,y,z) return(x+y+z), SIMPLIFY=TRUE)
fn1(1:3, 4:6,5)

[1] 10 12 14

fn2(1:3, 4:6,5)

[1] 10 12 14


You see that, fn1() and fn2() is giving same answer (vectorized?)  
despite of the fact that fn1() is not wrapped within Vectorize()  
function. Therefore I want to know: what additional thing this  
Vectorize() function brings on the table?


That is because you used "+"  which is "vectorized" to start with. Try  
is with "sum" and you will not be as "happy"

> sum(a=1:3, b=4:6, cc=7:9)
[1] 45

It removed all your structure.

> Vsum <-function(...) {what <- list(...); lenlist <- length(what);  
y<-matrix(unlist(what), ncol=lenlist); apply(y,1,sum)}

> Vsum(a=1:3, b=4:6, cc=7:9)
[1] 12 15 18
# Does not recycle as I might have expected, although it does recycle
> (Vsum( a=1:3, b=4:6, cc=7))
[1] 12  8 11


> (mapply(sum, a=1:3, b=4:6, cc=7:9))
 # also works and recycles as expected:
[1] 12 15 18

> (mapply(sum, a=1:3, b=4:6, cc=7))
[1] 12 14 16

# but _not_ VSum <- Vectorize(sum) for reasons not clear to me behaves  
the same as sum()




Thanks for your time.

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] Using NULL to my data?

2011-05-09 Thread Gabor Grothendieck
On Mon, May 9, 2011 at 12:59 PM, Nilza BARROS  wrote:
> Hi, Thanks for your attentio.
>
> I have the data frame below:
> 
>> head(Alldados)
>   Station_NO   date1 T_2M TMAX_2M TMIN_2M TD_2M PS FF_10M DD_10M
> 1 820420 110429/1200 22.5    NULL    22.4  22.2   NULL  0  0
> 2 820980 110429/1200 26.9    NULL    23.4  24.1 1010.2   2.91    360
> 3 821130 110429/1200 24.3    NULL    23.3  23.7   NULL   1.94    230
> 4 821410 110429/1200 24.4    NULL    23.7  24.2 1011.8   2.91    270
> 5 821450 110429/1200 28.2    NULL    21.1  25.8 1008.8  0  0
> 6 821810 110429/1200 23.3    NULL    22.8  22.9 1001.6  0  0
>   TOT_PRCP CLCL  date2
> 1    84.00 NULL 2011042912
> 2 2.00 NULL 2011042912
> 3 3.00 NULL 2011042912
> 4    12.00 NULL 2011042912
> 5 6.00 NULL 2011042912
> 6    38.00 NULL 2011042912
> 
> Now each line will feed my database. So I need to format each line like
> below:
>
> ===
>  [1] "INSERT INTO OBS
> (date,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO)
> VALUES (2011042912, 22.50,    NA, 22.40,22.20,   NA, 0.00, 0.00,36.00,
> NA,820420)"
>   [2] "INSERT INTO OBS
> (date,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO)
> VALUES (2011042912, 26.90,    NA, 23.40,24.10,1010.20, 2.91,360.00,16.00,
> NA,820980)"
>   [3] "INSERT INTO OBS
> (date,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO)
> VALUES (2011042912, 24.30,    NA, 23.30,23.70,   NA, 1.94,230.00,19.00,
> NA,821130)"
>   [4] "INSERT INTO OBS
> (date,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO)
> VALUES (2011042912, 24.40,    NA, 23.70,24.20,1011.80, 2.91,270.00,12.00,
> NA,821410)"
>   [5] "INSERT INTO OBS
> (date,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO)
> VALUES (2011042912, 28.20,    NA, 21.10,25.80,1008.80, 0.00, 0.00,31.00,
> NA,821450)"
>   [6] "INSERT INTO OBS
> (date,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO)
> VALUES (2011042912, 23.30,    NA, 22.80,22.90,1001.60, 0.00, 0.00,24.00,
> NA,821810)"
>   [7] "INSERT INTO OBS
> ===
>

Please

1. reduce Allados to a smaller number of columns and rows.  Say 10
rows and 3 columns such that it still exhibits the problem and then
show the result of dput:

dput(smallDF)

2. provide the R code that you would use with smallDF

3. explain what the problem is and how that differs from what you expect.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at 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.


Re: [R] Using NULL to my data?

2011-05-09 Thread Nilza BARROS
Hi, Thanks for your attentio.

I have the data frame below:

> head(Alldados)
  Station_NO   date1 T_2M TMAX_2M TMIN_2M TD_2M PS FF_10M DD_10M
1 820420 110429/1200 22.5NULL22.4  22.2   NULL  0  0
2 820980 110429/1200 26.9NULL23.4  24.1 1010.2   2.91360
3 821130 110429/1200 24.3NULL23.3  23.7   NULL   1.94230
4 821410 110429/1200 24.4NULL23.7  24.2 1011.8   2.91270
5 821450 110429/1200 28.2NULL21.1  25.8 1008.8  0  0
6 821810 110429/1200 23.3NULL22.8  22.9 1001.6  0  0
  TOT_PRCP CLCL  date2
184.00 NULL 2011042912
2 2.00 NULL 2011042912
3 3.00 NULL 2011042912
412.00 NULL 2011042912
5 6.00 NULL 2011042912
638.00 NULL 2011042912

Now each line will feed my database. So I need to format each line like
below:

===
 [1] "INSERT INTO OBS
(date,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO)
VALUES (2011042912, 22.50,NA, 22.40,22.20,   NA, 0.00, 0.00,36.00,
NA,820420)"
  [2] "INSERT INTO OBS
(date,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO)
VALUES (2011042912, 26.90,NA, 23.40,24.10,1010.20, 2.91,360.00,16.00,
NA,820980)"
  [3] "INSERT INTO OBS
(date,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO)
VALUES (2011042912, 24.30,NA, 23.30,23.70,   NA, 1.94,230.00,19.00,
NA,821130)"
  [4] "INSERT INTO OBS
(date,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO)
VALUES (2011042912, 24.40,NA, 23.70,24.20,1011.80, 2.91,270.00,12.00,
NA,821410)"
  [5] "INSERT INTO OBS
(date,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO)
VALUES (2011042912, 28.20,NA, 21.10,25.80,1008.80, 0.00, 0.00,31.00,
NA,821450)"
  [6] "INSERT INTO OBS
(date,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO)
VALUES (2011042912, 23.30,NA, 22.80,22.90,1001.60, 0.00, 0.00,24.00,
NA,821810)"
  [7] "INSERT INTO OBS
===

I hope it helps.

Best Regards,
Nilza

On Mon, May 9, 2011 at 1:47 PM, Gabor Grothendieck
wrote:

> You certainly can't assign a character string into a numeric column.
> There is no reason to expect that to work.
>
> Can you provide some clarity on what the problem is in terms of a very
> small self contained example explaining what you get and what you
> expected to get.
>
> Regards.
>
> On Mon, May 9, 2011 at 12:40 PM, Nilza BARROS 
> wrote:
> > Dear Ruser,
> >
> > Thank for your help.
> > I've just tried the command below and it works
> > Alldados[is.na(Alldados)]<-"NULL"
> >
> > But I am facing other problem, since I need to format my data before
> feeding
> > my database.
> >  I am using the command below:
> >
> > with(Alldados,sprintf("INSERT INTO OBS
> >
> (date,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO)
> > VALUES (%s, %5.2f, %5.2f, %5.2f,%5.2f,%5.2f,%5.2f,%5.2f,%5.2f,%5.2f,%s)",
> >
> >
> date2,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO))
> >
> > But it is not working anymore. Because now the same field can be numeric
> or
> > character.
> > How can I use the format command above the allow it.
> >
> > I really appreciate any help.
> > Nilza
> >
> >
> >
> >
> >
> > On Mon, May 9, 2011 at 12:55 PM, David Winsemius  >wrote:
> >
> >>
> >> On May 9, 2011, at 10:07 AM, Nilza BARROS wrote:
> >>
> >> Dear R users,
> >>>
> >>> I am reading data from a file where there are some missing that are
> >>> represented by -.00.
> >>> I am using the command below.
> >>> =My original data ===
> >>>
> >>> PARM = TMPC;T12X;T12N;DWPC;PALT;SKNT;DRCT;P24M;CLCL
> >>>
> >>
> >> snipped
> >>
> >>
> >> But  I need to feed my database. These missings should be represented by
> >>> NULL.
> >>> I mean, all "NA" should be replaced by "NULL" in my database.
> >>>
> >>
> >> Do you mean a string that is spelled "NULL"
> >>
> >> If so, try:
> >>
> >> dfrm[is.na(dfrm)] <- "NULL"
> >>
> >>
> >> I am trying the command below to pick up the rows and columns with NA
> but I
> >>> don't know how to fill the original data :
> >>>
> >>> which(is.na(Alldados),arr.ind=TRUE)
> >>>
> >>> But I don't know how to replace each NA with NULL. I tried using
> as.null
> >>> but
> >>> NA is not replace at all.
> >>>
> >>
> >> If you set a column of a data.frame to NULL , it will erase it.
> >>
> >>
> >>
> >>> I hope someone could help me.
> >>>
> >>> Best Wishes,
> >>> Nilza Barros
> >>>
> >>>
> >> David Winsemius, MD
> >> West Hartford, CT
> >>
> >>
> >
> >
> > --
> > Abraço,
> > Nilza Barros
> >
>  >[[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 

Re: [R] Vermunt's LEM in R

2011-05-09 Thread Wincent
What is L_square? Is it Likelihood ratio/deviance statistic which is
reported by poLCA?
The predcell component contains observed and expected, isn't it easy
to get the residuals?

If you want the logit/logistic model, glm or lrm (rms) can do the job.

It is unrealistic to expect different software report the exact
result, though most of them report the most important and basic
statistics.

On 10 May 2011 00:12, David Joubert  wrote:
>
>
> Basically I do LCA, followed by some kind of analysis intended to validate 
> the solutions. For example, I would create latent class solutions for each 
> gender based on four dichotomic indicators of psychosis. Next, I would look 
> at the interaction of current psychiatric status (the classes) and past 
> psychiatric diagnosis to predict institutional treatment use (logit or 
> logistic models). poLCA is a little limited for this purpose; I would have to 
> use it in combination with some other package. For example, it doesn't 
> provide residuals for the indicators, or the Cressie-Read statistic.
>
> David Joubert
>
>
> Date: Fri, 6 May 2011 09:56:05 +0200
> Subject: Re: [R] Vermunt's LEM in R
> From: i.vis...@uva.nl
> To: ronggui.hu...@gmail.com
> CC: jo...@hotmail.com; r-help@r-project.org
>
> poLCA is an option, as is randomLCA, flexmix, and depmixS4, and there are 
> likely to be more
> What specific models are you interested in?
> Best, Ingmar
>
> On Fri, May 6, 2011 at 6:13 AM, Wincent  wrote:
>
> I guess LEM is a software for latent class analysis. If so, you may
>
> want to have a look at poLCA package.
>
>
>
> Regards
>
> Ronggui
>
>
>
> On 5 May 2011 23:34, David Joubert  wrote:
>
>>
>
>> Hello-
>
>>
>
>> Does anyone know of packages that could emulate what J. Vermunt's LEM does ? 
>> What is the closest relative in R ?
>
>> I use both R and LEM but have trouble transforming my multiway tables in R 
>> into a .dat file compatible with LEM.
>
>>
>
>> Thanks,
>
>>
>
>> David Joubert
>
>>
>
>>        [[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.
>
>>
>
>
>
>
>
>
>
> --
>
> Wincent Ronggui HUANG
>
> Sociology Department of Fudan University
>
> PhD of City University of Hong Kong
>
> http://asrr.r-forge.r-project.org/rghuang.html
>
>
>
> __
>
> R-help@r-project.org mailing list
>
> https://stat.ethz.ch/mailman/listinfo/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.
>



-- 
Wincent Ronggui HUANG
Sociology Department of Fudan University
PhD of City University of Hong Kong
http://asrr.r-forge.r-project.org/rghuang.html

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


Re: [R] Using NULL to my data?

2011-05-09 Thread Gabor Grothendieck
You certainly can't assign a character string into a numeric column.
There is no reason to expect that to work.

Can you provide some clarity on what the problem is in terms of a very
small self contained example explaining what you get and what you
expected to get.

Regards.

On Mon, May 9, 2011 at 12:40 PM, Nilza BARROS  wrote:
> Dear Ruser,
>
> Thank for your help.
> I've just tried the command below and it works
> Alldados[is.na(Alldados)]<-"NULL"
>
> But I am facing other problem, since I need to format my data before feeding
> my database.
>  I am using the command below:
>
> with(Alldados,sprintf("INSERT INTO OBS
> (date,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO)
> VALUES (%s, %5.2f, %5.2f, %5.2f,%5.2f,%5.2f,%5.2f,%5.2f,%5.2f,%5.2f,%s)",
>
> date2,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO))
>
> But it is not working anymore. Because now the same field can be numeric or
> character.
> How can I use the format command above the allow it.
>
> I really appreciate any help.
> Nilza
>
>
>
>
>
> On Mon, May 9, 2011 at 12:55 PM, David Winsemius 
> wrote:
>
>>
>> On May 9, 2011, at 10:07 AM, Nilza BARROS wrote:
>>
>> Dear R users,
>>>
>>> I am reading data from a file where there are some missing that are
>>> represented by -.00.
>>> I am using the command below.
>>> =My original data ===
>>>
>>> PARM = TMPC;T12X;T12N;DWPC;PALT;SKNT;DRCT;P24M;CLCL
>>>
>>
>> snipped
>>
>>
>> But  I need to feed my database. These missings should be represented by
>>> NULL.
>>> I mean, all "NA" should be replaced by "NULL" in my database.
>>>
>>
>> Do you mean a string that is spelled "NULL"
>>
>> If so, try:
>>
>> dfrm[is.na(dfrm)] <- "NULL"
>>
>>
>> I am trying the command below to pick up the rows and columns with NA but I
>>> don't know how to fill the original data :
>>>
>>> which(is.na(Alldados),arr.ind=TRUE)
>>>
>>> But I don't know how to replace each NA with NULL. I tried using as.null
>>> but
>>> NA is not replace at all.
>>>
>>
>> If you set a column of a data.frame to NULL , it will erase it.
>>
>>
>>
>>> I hope someone could help me.
>>>
>>> Best Wishes,
>>> Nilza Barros
>>>
>>>
>> David Winsemius, MD
>> West Hartford, CT
>>
>>
>
>
> --
> Abraço,
> Nilza Barros
>
>        [[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.
>
>



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at 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.


Re: [R] Using NULL to my data?

2011-05-09 Thread Nilza BARROS
Dear Ruser,

Thank for your help.
I've just tried the command below and it works
Alldados[is.na(Alldados)]<-"NULL"

But I am facing other problem, since I need to format my data before feeding
my database.
 I am using the command below:

with(Alldados,sprintf("INSERT INTO OBS
(date,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO)
VALUES (%s, %5.2f, %5.2f, %5.2f,%5.2f,%5.2f,%5.2f,%5.2f,%5.2f,%5.2f,%s)",

date2,T_2M,TMAX_2M,TMIN_2M,TD_2M,PS,FF_10M,DD_10M,TOT_PRCP,CLCL,Station_NO))

But it is not working anymore. Because now the same field can be numeric or
character.
How can I use the format command above the allow it.

I really appreciate any help.
Nilza





On Mon, May 9, 2011 at 12:55 PM, David Winsemius wrote:

>
> On May 9, 2011, at 10:07 AM, Nilza BARROS wrote:
>
> Dear R users,
>>
>> I am reading data from a file where there are some missing that are
>> represented by -.00.
>> I am using the command below.
>> =My original data ===
>>
>> PARM = TMPC;T12X;T12N;DWPC;PALT;SKNT;DRCT;P24M;CLCL
>>
>
> snipped
>
>
> But  I need to feed my database. These missings should be represented by
>> NULL.
>> I mean, all "NA" should be replaced by "NULL" in my database.
>>
>
> Do you mean a string that is spelled "NULL"
>
> If so, try:
>
> dfrm[is.na(dfrm)] <- "NULL"
>
>
> I am trying the command below to pick up the rows and columns with NA but I
>> don't know how to fill the original data :
>>
>> which(is.na(Alldados),arr.ind=TRUE)
>>
>> But I don't know how to replace each NA with NULL. I tried using as.null
>> but
>> NA is not replace at all.
>>
>
> If you set a column of a data.frame to NULL , it will erase it.
>
>
>
>> I hope someone could help me.
>>
>> Best Wishes,
>> Nilza Barros
>>
>>
> David Winsemius, MD
> West Hartford, CT
>
>


-- 
Abraço,
Nilza Barros

[[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] Vectorizing a function: what does it mean?

2011-05-09 Thread Ron Michael
Dear all, I would really appreciate if somebody can help me to understand what 
does the phrase "Vectorize your function" mean? And what is the job of 
Vectorize() function in doing that? I have read many threads where experts 
suggest to Vectorize the function, which will speed up entire calculation (and 
more elegant ofcourse.)

I used to think that vectorizing function means, to create a function such a 
way so that if input(s) are vector then this function will also return a vector 
output (without having any extra effort like use of 'for' loop etc.) Is this 
understanding correct?

Here I have tried 2 essentially similar functions:

> fn1 <- function(x,y,z) return(x+y+z)
> fn2 <- Vectorize(function(x,y,z) return(x+y+z), SIMPLIFY=TRUE)
> fn1(1:3, 4:6,5)
[1] 10 12 14
> fn2(1:3, 4:6,5)
[1] 10 12 14


You see that, fn1() and fn2() is giving same answer (vectorized?) despite of 
the fact that fn1() is not wrapped within Vectorize() function. Therefore I 
want to know: what additional thing this Vectorize() function brings on the 
table?

Thanks for your time.

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


Re: [R] Vermunt's LEM in R

2011-05-09 Thread David Joubert


Basically I do LCA, followed by some kind of analysis intended to validate the 
solutions. For example, I would create latent class solutions for each gender 
based on four dichotomic indicators of psychosis. Next, I would look at the 
interaction of current psychiatric status (the classes) and past psychiatric 
diagnosis to predict institutional treatment use (logit or logistic models). 
poLCA is a little limited for this purpose; I would have to use it in 
combination with some other package. For example, it doesn't provide residuals 
for the indicators, or the Cressie-Read statistic. 

David Joubert  

  
Date: Fri, 6 May 2011 09:56:05 +0200
Subject: Re: [R] Vermunt's LEM in R
From: i.vis...@uva.nl
To: ronggui.hu...@gmail.com
CC: jo...@hotmail.com; r-help@r-project.org

poLCA is an option, as is randomLCA, flexmix, and depmixS4, and there are 
likely to be more
What specific models are you interested in?
Best, Ingmar

On Fri, May 6, 2011 at 6:13 AM, Wincent  wrote:

I guess LEM is a software for latent class analysis. If so, you may

want to have a look at poLCA package.



Regards

Ronggui



On 5 May 2011 23:34, David Joubert  wrote:

>

> Hello-

>

> Does anyone know of packages that could emulate what J. Vermunt's LEM does ? 
> What is the closest relative in R ?

> I use both R and LEM but have trouble transforming my multiway tables in R 
> into a .dat file compatible with LEM.

>

> Thanks,

>

> David Joubert

>

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

>







--

Wincent Ronggui HUANG

Sociology Department of Fudan University

PhD of City University of Hong Kong

http://asrr.r-forge.r-project.org/rghuang.html



__

R-help@r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/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] Vermunt's LEM in R

2011-05-09 Thread David Joubert

Sure, sorry for not clarifying from the beginning. 

LEM is a rather powerful software for conducting general loglinear analysis, 
including latent class, logit, latent Markov, Event History models, etc. It's 
very polyvalent. 

Link to the software and document is at 
http://www.tilburguniversity.edu/nl/over-tilburg-university/schools/socialsciences/organisatie/departementen/mto/software2.html.
 

Since I use R for other types of analyses, it would be good to have the 
equivalent in R without having to go back and forth between LEM and R. The 
packages that do LCA in R miss several important features (L-square statistic, 
Entropy, Cressie-Read, residuals, etc.). 

Thanks,

David Joubert

> Date: Fri, 6 May 2011 09:37:02 +1000
> From: a.robin...@ms.unimelb.edu.au
> To: jo...@hotmail.com
> CC: r-help@r-project.org
> Subject: Re: [R] Vermunt's LEM in R
> 
> Hi David,
> 
> you might have more luck with your request if you tell us what
> Vermunt's LEM *does*, and provided some links to introductory reading
> material ...
> 
> Cheers
> 
> Andrew
> 
> On Thu, May 05, 2011 at 03:34:02PM +, David Joubert wrote:
> > 
> > Hello-
> > 
> > Does anyone know of packages that could emulate what J. Vermunt's LEM does 
> > ? What is the closest relative in R ?
> > I use both R and LEM but have trouble transforming my multiway tables in R 
> > into a .dat file compatible with LEM. 
> > 
> > Thanks,
> > 
> > David Joubert
> >   
> > [[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.
> 
> -- 
> Andrew Robinson  
> Program Manager, ACERA 
> Department of Mathematics and StatisticsTel: +61-3-8344-6410
> University of Melbourne, VIC 3010 Australia   (prefer email)
> http://www.ms.unimelb.edu.au/~andrewpr  Fax: +61-3-8344-4599
> http://www.acera.unimelb.edu.au/
> 
> Forest Analytics with R (Springer, 2011) 
> http://www.ms.unimelb.edu.au/FAwR/
> Introduction to Scientific Programming and Simulation using R (CRC, 2009): 
> http://www.ms.unimelb.edu.au/spuRs/
  
[[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] Using NULL to my data?

2011-05-09 Thread David Winsemius


On May 9, 2011, at 10:07 AM, Nilza BARROS wrote:


Dear R users,

I am reading data from a file where there are some missing that are
represented by -.00.
I am using the command below.
=My original data ===

PARM = TMPC;T12X;T12N;DWPC;PALT;SKNT;DRCT;P24M;CLCL


snipped

But  I need to feed my database. These missings should be  
represented by

NULL.
I mean, all "NA" should be replaced by "NULL" in my database.


Do you mean a string that is spelled "NULL"

If so, try:

dfrm[is.na(dfrm)] <- "NULL"

I am trying the command below to pick up the rows and columns with  
NA but I

don't know how to fill the original data :

which(is.na(Alldados),arr.ind=TRUE)

But I don't know how to replace each NA with NULL. I tried using  
as.null but

NA is not replace at all.


If you set a column of a data.frame to NULL , it will erase it.



I hope someone could help me.

Best Wishes,
Nilza Barros



David Winsemius, MD
West Hartford, CT

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


Re: [R] Pretty printing numbers

2011-05-09 Thread Peter Ehlers

On 2011-05-08 16:41, Worik R wrote:

Friends

I am trying to format a number to a string so 2189.745 goes to "2,189.35"
and 309283.929 goes to "309,283.93"

I have tried to use formatC(X, big.mark=",",drop0trailing=FALSE, format="f")
but it does not get the number of decimals correct.  Specifying digits does
not work as that is significant digits.  I could use a switch statement
switching on the size of the number to be formated to set the digits
parameter but that is complex and leaves me insecure that thre may be other
problems I have not uncovered.


I see that you've had the solution you seek in terms of round(),
but what exactly is wrong with the 'digits' argument? It works
for me in the cases you cite. (Note that format = "f" is handled
differently from other formats, according to ?formatC.)

Peter Ehlers



Is there a simple way of using library functions to insert big.marks and get
the number of trailing digits correct?  Perhaps some way of using sprintf?

cheers
Worik

[[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] Round down to earliest hour or half hour

2011-05-09 Thread Jannis
I would use package chron and trunc()

One example from the help of trunc.times (modified):

lirary(chron)
tt <- times(c("12:13:14", "15:46:17"))
trunc(tt, times("00:30:00"))


HTH
Jannis

--- Schatzi  schrieb am Mo, 9.5.2011:

> Von: Schatzi 
> Betreff: [R] Round down to earliest hour or half hour
> An: r-help@r-project.org
> Datum: Montag, 9. Mai, 2011 14:06 Uhr
> I have times and would like to round
> down to the earliest 30 minute
> increment. For instance, a time of 
> 2011-04-28 09:02:00
> (the as.numeric value = 1303999320)
> I would like it to be rounded down to:
> 2011-04-28 09:00:00
> (the as.numeric value = 1303999200)
> 
> Any ideas of how to do this?
> 
> -
> In theory, practice and theory are the same. In practice,
> they are not - Albert Einstein
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Round-down-to-earliest-hour-or-half-hour-tp3509374p3509374.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] Odp: Using NULL to my data?

2011-05-09 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 09.05.2011 16:07:27:

> Nilza BARROS  
> Odeslal: r-help-boun...@r-project.org
> 
> 09.05.2011 16:07
> 
> 
> Dear R users,
> 
> I am reading data from a file where there are some missing that are
> represented by -.00.
> I am using the command below.
> =My original data ===
> 
> PARM = TMPC;T12X;T12N;DWPC;PALT;SKNT;DRCT;P24M;CLCL
> 
> 
> STNYYMMDD/HHMM  TMPC T12X T12N DWPC PALT
> SKNT
> DRCT P24M CLCL
>  820420110429/1200 22.50 -.0022.4022.20 -.00
> 0.00
> 0.0084.00 4.00
>  820980110429/1200 26.90 -.0023.4024.10  1010.20
> 2.91
>   360.00 2.00 6.00
>  821130110429/1200 24.30 -.0023.3023.70 -.00
> 1.94
>   230.00 3.00 4.00
>  821410110429/1200 24.40 -.0023.7024.20  1011.80
> 2.91
> ===
> 
> dados<-read.table
> ("2011042912_teste.dat",sep='',fill=TRUE,na.strings="-.00",skip=4)
> head(dados)
>   V1  V2   V3 V4   V5   V6 V7   V8 group
> 1 820420 110429/1200 22.5 NA 22.4 22.2 NA 0.00 1
> 2  0   84.00  4.0 NA   NA   NA NA   NA 1
> 3 820980 110429/1200 26.9 NA 23.4 24.1 1010.2 2.91 2
> 43602.00  6.0 NA   NA   NA NA   NA 2
> 5 821130 110429/1200 24.3 NA 23.3 23.7 NA 1.94 3
> 62303.00  4.0 NA   NA   NA NA   NA 3
> =
> After some procedures a have the data as below:
> > head(Alldados)
> 
> 
>   Station_NO   date1 T_2M TMAX_2M TMIN_2M TD_2M PS FF_10M DD_10M
> 1 820420 110429/1200 22.5  NA22.4  22.2 NA   0.00  0
> 2 820980 110429/1200 26.9  NA23.4  24.1 1010.2   2.91360
> 3 821130 110429/1200 24.3  NA23.3  23.7 NA   1.94230
> 4 821410 110429/1200 24.4  NA23.7  24.2 1011.8   2.91270
> 5 821450 110429/1200 28.2  NA21.1  25.8 1008.8   0.00  0
> 6 821810 110429/1200 23.3  NA22.8  22.9 1001.6   0.00  0
>   TOT_PRCP CLCL  date2
> 184.00   NA 2011042912
> 2 2.00   NA 2011042912
> 3 3.00   NA 2011042912
> 412.00   NA 2011042912
> 5 6.00   NA 2011042912
> 638.00   NA 2011042912
> 
> But  I need to feed my database. These missings should be represented by
> NULL.
> I mean, all "NA" should be replaced by "NULL" in my database.
> I am trying the command below to pick up the rows and columns with NA 
but I
> don't know how to fill the original data :
> 
> which(is.na(Alldados),arr.ind=TRUE)
> 
> But I don't know how to replace each NA with NULL. I tried using as.null 
but
> NA is not replace at all.

Why do you want that? NULL is reserved for objects which emerged from 
undefined function results. See its help page.

As such you can not have vector of NULLs.

> rep(NULL, 10)
NULL
> rep(NA, 10)
 [1] NA NA NA NA NA NA NA NA NA NA

Maybe you want to replace NA with zero. If yes 

Alldados[is.na(Alldados)]<-0

could be what you want.

Regards
Petr


> 
> I hope someone could help me.
> 
> Best Wishes,
> Nilza Barros
> 
>[[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] Time Series

2011-05-09 Thread Uwe Ligges
Although this is not an R question actually, if I get such a 
question in our consulting centre, my advice is:


Present a table of your 4  observations and that's it from a 
quantitative point of view. There is no sense in modelling or testing 
with 4 observations.


Best,
Uwe Ligges




On 09.05.2011 16:20, Nicole Gross-Camp wrote:

I have what I hope is a simple question - is it possible to do time series
analysis on a small data set specifically only four data points?



I have collected human threat data (mean number of threats per kilometre
walked/ survey) every 3 months in eight different sites (four with an
experimental element and four control sites). I am trying to determine the
best way to determine if there is a trend in the data though from what I've
seen of TSA, our data set is too small. I did a simple paired t-test on the
first and average of following three surveys that shows no significant
difference but it of course ignores the detail of the latter three surveys.



I am not sure how to organize the data for importation into R. I've looked
at Crawley and one of Zuur publications but the TS data they work with is
much longer term and not over several (independent) sites.



Any advice, help, or direction is much appreciated!



Best,

Nicole





Nicole Gross-Camp, PhD

Senior Research Associate

University of East Anglia

Norwich

Rwanda: +250 (0)783647398

Skype: nicolegross-camp



Based in Rwanda from September 2010 through July 2011:

BP 512

Butare

Rwanda



personal website:
http://www.uea.ac.uk/dev/People/Research+Associate/Nicole+Gross-Camp#info



project website:

www.ReDirectRwanda.com




[[alternative HTML version deleted]]

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


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


Re: [R] %in% operator - NOT IN

2011-05-09 Thread Karl Ove Hufthammer
Dan Abner wrote:

> I am attempting to use the %in% operator with the ! to produce a NOT IN
> type of operation.

Just use the ‘%nin‰’ operator in the ‘Hmisc’ package. :-)

-- 
Karl Ove Hufthammer

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

2011-05-09 Thread Nicole Gross-Camp
I have what I hope is a simple question - is it possible to do time series
analysis on a small data set specifically only four data points? 

 

I have collected human threat data (mean number of threats per kilometre
walked/ survey) every 3 months in eight different sites (four with an
experimental element and four control sites). I am trying to determine the
best way to determine if there is a trend in the data though from what I've
seen of TSA, our data set is too small. I did a simple paired t-test on the
first and average of following three surveys that shows no significant
difference but it of course ignores the detail of the latter three surveys. 

 

I am not sure how to organize the data for importation into R. I've looked
at Crawley and one of Zuur publications but the TS data they work with is
much longer term and not over several (independent) sites.

 

Any advice, help, or direction is much appreciated!

 

Best,

Nicole

 



Nicole Gross-Camp, PhD

Senior Research Associate

University of East Anglia

Norwich

Rwanda: +250 (0)783647398

Skype: nicolegross-camp

 

Based in Rwanda from September 2010 through July 2011:

BP 512

Butare

Rwanda

 

personal website:
http://www.uea.ac.uk/dev/People/Research+Associate/Nicole+Gross-Camp#info

 

project website: 

www.ReDirectRwanda.com 

 


[[alternative HTML version deleted]]

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


Re: [R] How to alter circle size

2011-05-09 Thread Dat Mai
Thanks for the help! Though, when I do this, I get a message saying "Error
using packet 1 value where TRUE/FALSE." Would that have anything to do with
this set of code?

On Sun, May 8, 2011 at 3:00 PM, Deepayan Sarkar
wrote:

> On Fri, May 6, 2011 at 10:21 PM, Dat Mai  wrote:
> > Hello all,
> >
> > I'm trying  to create a heatmap using 2 matrices I have: z and v. Both
> > matrices represent different correlations for the same independent
> > variables. The problem I have is that I wish to have the values from
> matrix
> > z to be represented by color intensity while having the values from
> matrix v
> > to be represented by circle size. I currently have the following in front
> of
> > me and an unsure of what to add or change in order to achieve that goal.
> >
> > panel.corrgram.2 =
> > function(x, y, z, subscripts, at = pretty(z), scale = 0.8, ...)
> > {
> >  require("grid", quietly = TRUE)
> >  x <- as.numeric(x)[subscripts]
> >  y <- as.numeric(y)[subscripts]
> >  z <- as.numeric(z)[subscripts]
> >  zcol <- level.colors(z, at = at, ...)
> >  for (i in seq(along = z))
> >  {
> >lims <- range(0, z[i])
> >tval <- 2 * base::pi * seq(from = lims[1], to = lims[2], by = 0.01)
> >grid.polygon(x = x[i] + .5 * scale * c(0, sin(tval)),
> >  y = y[i] + .5 * scale * c(0, cos(tval)),
> >  default.units = "native",
> >  gp = gpar(fill = zcol[i]))
> >grid.circle(x = x[i], y = y[i], r = .5 * scale,
> >  default.units = "native")
> >  }
> > }
>
> Probably this modification
>
> panel.corrgram.2 <-
>function(x, y, z, v, subscripts, at = pretty(v), scale = 0.8, ...)
> {
>require("grid", quietly = TRUE)
>x <- as.numeric(x)[subscripts]
>y <- as.numeric(y)[subscripts]
>z <- as.numeric(z)[subscripts]
> zcol <- level.colors(v, at = at, ...)
>
>
>
>
> followed by
>
> levelplot(signif(z,3), v = v, panel = panel.corrgram.2, ...)
>
> will do it.
>
> -Deepayan
>
>
> >
> > k=levelplot(signif(z,3), scales = list(x = list(rot = 45)),
> > col.regions=col.sch, panel = panel.corrgram.2,
> > label = num.circ, xlab="", ylab="", main=paste(output,"receptor
> response"))
> > print(k)
> >
> > --
> > Best,
> > Dat Mai
> > PhD Rotation Student
> > Albert Einstein College of Medicine
> >
> >[[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.
> >
>



-- 
Best,
Dat Mai
PhD Rotation Student
Albert Einstein College of Medicine

[[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] Summarising by group

2011-05-09 Thread Ista Zahn
Trolling? (but see in line below)

On Mon, May 9, 2011 at 5:12 AM, Martyn Byng  wrote:
> I wonder if someone with more experience than me on using R to summarise
> by group wants to post a reply to this
>
> http://www.analyticbridge.com/group/sasandstatisticalprogramming/forum/t
> opics/why-still-use-sas-with-a-lot
>
> To save everyone having to follow the link, the text is copied below
>
> "SAS has some nice features, such as the SQL procedure or simple "group
> by" features. Try to compute correlations "by group" in R: say you have
> 2,000 groups, 2 variables e.g. salary and education level, and 2 million
> observations - you want to compute correlation between salary and
> education within each group.
>
> It is not obvious, your best bet is to use some R package

The wealth of R packages is a core strength of the platform. It is not
a disadvantage to have a wealth of well-developed code for almost any
statistical application.

(see sample
> code on Analyticbridge to do it), and the solution is painful,

Well, the Analyticbridge code is painful, but that example says far
more about the person who wrote it that it does about R. All they
really needed to do was

v <- ddply(xx, .(country), summarize,
   COR = cor(income, age),
   MEAN_age = mean(age),
   MEAN_income = mean(income),
   MAX_income = max(income),
   STDEV_income = sd(income))

I'm not intested in signing up so I can post a reply to the orignial
post, but feel free to copy my answer there if you want.

Best,
Ista

you can
> not return both correlation and stdev "by group", as the function can
> return only one argument, not a vector. So if you want to return not
> just two, but say 100 metrics, it becomes a nightmare."

Wrong, see example above.

Best,
Ista
>
>
>
> 
> The Numerical Algorithms Group Ltd is a company registered in England
> and Wales with company number 1249803. The registered office is:
> Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.
>
> This e-mail has been scanned for all viruses by Star. Th...{{dropped:4}}
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

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


Re: [R] maximum likelihood convergence reproducing Anderson Blundell 1982 Econometrica R vs Stata

2011-05-09 Thread peter dalgaard
Hmm, I tried replacing the x's in the model with their principal component 
scores, and suddenly everything converges as a greased lightning:

> Z <- princomp(cbind(x1,x2,x3))$scores
> Z <- as.data.frame(princomp(cbind(x1,x2,x3))$scores)
> names(Z)<- letters[1:3]
> optimx(rep(0,8),lnl, hessian=TRUE, y1=y1, y2=y2,
+ x1=Z$a, x2=Z$b, x3=Z$c, method="BFGS")

par
1 0.59107682, 0.01043568, -0.20639153, 0.25902746, 0.24675162, -0.01426477, 
0.18045177, -0.23657327
fvalues method fns grs itns conv KKT1 KKT2 xtimes
1 -76.73878   BFGS 157  37 NULL0 TRUE TRUE  0.055
Warning messages:
1: In max(logpar) : no non-missing arguments to max; returning -Inf
2: In min(logpar) : no non-missing arguments to min; returning Inf

The likelihood appears to be spot on, but, obviously, the parameter estimates 
need to be back-transformed to the original x1,x2,x3 system. I'll leave that as 
the proverbial "exercise for the reader"...

However, the whole thing leads me to a suspicion that maybe our numerical 
gradients are misbehaving in cases with high local collinearity?

-pd

On May 9, 2011, at 13:40 , Alex Olssen wrote:

> Hi Mike,
> 
> Mike said
> "is this it, page 1559?"
> 
> That is the front page yes, page 15*6*9 has the table, of which the
> model labelled 18s is the one I replicated.
> 
> "did you actually cut/paste code anywhere and is your first
> coefficient -.19 or -.019?
> Presumably typos would be one possible problem."
> 
> -0.19 is not a typo, it is pi10 in the paper, and a1 in my Stata
> estimation - as far as I can tell cutting and pasting is not the
> problem.
> 
> "generally it helps if we could at least see the equations to check your
> code against typos ( note page number ?) in lnl that may fix part of the
> mystery.  Is full text available
> on author's site, doesn't come up on citeseer AFAICT,"
> 
> Unfortunately I do not know of any place to get the full version of
> this paper that doesn't require access to a database such as JSTOR.
> The fact that this likelihood function reproduces the published
> results in Stata makes me confident that it is correct - I also have
> read a lot on systems estimation and it is a pretty standard
> likelihood function.
> 
> "I guess one question would be " what is beta" in lnl supposed to be -
> it isn't used anywhere but I will also mentioned I'm not that familiar
> with the R code ( I'm trying to work through this to learn R and the
> optimizers).
> 
> maybe some words would help, is sigma supposed to be 2x2 or 8x8 and what are
> e1 and e2 supposed to be?"
> 
> The code above is certainly not as elegant as it could be - in this
> case the beta is rather superfluous.  It is just a vector to hold
> parameters - but since I called all the parameters theta anyway there
> is no need for it.  e1 and e2 are the residuals from the first and
> second equations of the system.  Sigma is a 2x2 matrix which is the
> outer product of the two vectors of residuals.
> 
> Kind regards,
> 
> Alex
> 
> 
> 
> On 9 May 2011 23:12, Mike Marchywka  wrote:
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> Date: Mon, 9 May 2011 22:06:38 +1200
>>> From: alex.ols...@gmail.com
>>> To: pda...@gmail.com
>>> CC: r-help@r-project.org; da...@otter-rsch.com
>>> Subject: Re: [R] maximum likelihood convergence reproducing Anderson 
>>> Blundell 1982 Econometrica R vs Stata
>>> 
>>> Peter said
>>> 
>>> "Ahem! You might get us interested in your problem, but not to the
>>> level that we are going to install Stata and Tsp and actually dig out
>>> and study the scientific paper you are talking about. Please cite the
>>> results and explain the differences."
>>> 
>>> Apologies Peter, will do,
>>> 
>>> The results which I can emulate in Stata but not (yet) in R are reported 
>>> below.
>> 
>> did you actually cut/paste code anywhere and is your first coefficient -.19 
>> or -.019?
>> Presumably typos would be one possible problem.
>> 
>>> They come from Econometrica Vol. 50, No. 6 (Nov., 1982), pp. 1569
>> 
>> 
>> is this it, page 1559?
>> 
>> http://www.jstor.org/pss/1913396
>> 
>> generally it helps if we could at least see the equations to check your
>> code against typos ( note page number ?) in lnl that may fix part of the
>> mystery.  Is full text available
>> on author's site, doesn't come up on citeseer AFAICT,
>> 
>> 
>> http://citeseerx.ist.psu.edu/search?q=blundell+1982&sort=ascdate
>> 
>> I guess one question would be " what is beta" in lnl supposed to be -
>> it isn't used anywhere but I will also mentioned I'm not that familiar
>> with the R code ( I'm trying to work through this to learn R and the 
>> optimizers).
>> 
>> maybe some words would help, is sigma supposed to be 2x2 or 8x8 and what are
>> e1 and e2 supposed to be?
>> 
>> 
>> 
>> 
>>> 
>>> TABLE II - model 18s
>>> 
>>> coef std err
>>> p10 -0.19 0.078
>>> p11 0.220 0.019
>>> p12 -0.148 0.021
>>> p13 -0.072
>>> p20 0

[R] Using NULL to my data?

2011-05-09 Thread Nilza BARROS
Dear R users,

I am reading data from a file where there are some missing that are
represented by -.00.
I am using the command below.
=My original data ===

PARM = TMPC;T12X;T12N;DWPC;PALT;SKNT;DRCT;P24M;CLCL


STNYYMMDD/HHMM  TMPC T12X T12N DWPC PALT
SKNT
DRCT P24M CLCL
 820420110429/1200 22.50 -.0022.4022.20 -.00
0.00
0.0084.00 4.00
 820980110429/1200 26.90 -.0023.4024.10  1010.20
2.91
  360.00 2.00 6.00
 821130110429/1200 24.30 -.0023.3023.70 -.00
1.94
  230.00 3.00 4.00
 821410110429/1200 24.40 -.0023.7024.20  1011.80
2.91
===

dados<-read.table("2011042912_teste.dat",sep='',fill=TRUE,na.strings="-.00",skip=4)
head(dados)
  V1  V2   V3 V4   V5   V6 V7   V8 group
1 820420 110429/1200 22.5 NA 22.4 22.2 NA 0.00 1
2  0   84.00  4.0 NA   NA   NA NA   NA 1
3 820980 110429/1200 26.9 NA 23.4 24.1 1010.2 2.91 2
43602.00  6.0 NA   NA   NA NA   NA 2
5 821130 110429/1200 24.3 NA 23.3 23.7 NA 1.94 3
62303.00  4.0 NA   NA   NA NA   NA 3
=
After some procedures a have the data as below:
> head(Alldados)


  Station_NO   date1 T_2M TMAX_2M TMIN_2M TD_2M PS FF_10M DD_10M
1 820420 110429/1200 22.5  NA22.4  22.2 NA   0.00  0
2 820980 110429/1200 26.9  NA23.4  24.1 1010.2   2.91360
3 821130 110429/1200 24.3  NA23.3  23.7 NA   1.94230
4 821410 110429/1200 24.4  NA23.7  24.2 1011.8   2.91270
5 821450 110429/1200 28.2  NA21.1  25.8 1008.8   0.00  0
6 821810 110429/1200 23.3  NA22.8  22.9 1001.6   0.00  0
  TOT_PRCP CLCL  date2
184.00   NA 2011042912
2 2.00   NA 2011042912
3 3.00   NA 2011042912
412.00   NA 2011042912
5 6.00   NA 2011042912
638.00   NA 2011042912

But  I need to feed my database. These missings should be represented by
NULL.
I mean, all "NA" should be replaced by "NULL" in my database.
I am trying the command below to pick up the rows and columns with NA but I
don't know how to fill the original data :

which(is.na(Alldados),arr.ind=TRUE)

But I don't know how to replace each NA with NULL. I tried using as.null but
NA is not replace at all.

I hope someone could help me.

Best Wishes,
Nilza Barros

[[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] Round down to earliest hour or half hour

2011-05-09 Thread Schatzi
I have times and would like to round down to the earliest 30 minute
increment. For instance, a time of 
2011-04-28 09:02:00
(the as.numeric value = 1303999320)
I would like it to be rounded down to:
2011-04-28 09:00:00
(the as.numeric value = 1303999200)

Any ideas of how to do this?

-
In theory, practice and theory are the same. In practice, they are not - Albert 
Einstein
--
View this message in context: 
http://r.789695.n4.nabble.com/Round-down-to-earliest-hour-or-half-hour-tp3509374p3509374.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] Recursive Indexing Failed

2011-05-09 Thread Alaios
Thank you very much all for your time.
For now I am doing this with a simple for loop as some times lapply,sapply 
makes things more complex 
(or in other words I am not that experience using it).

Best REgards
Alex

--- On Mon, 5/9/11, Patrick Breheny  wrote:

> From: Patrick Breheny 
> Subject: Re: [R] Recursive Indexing Failed
> To: "Duncan Murdoch" 
> Cc: "Alaios" , "R-help@r-project.org" 
> Date: Monday, May 9, 2011, 2:57 PM
> On 05/09/2011 09:52 AM, Duncan
> Murdoch wrote:
> >> In general, the expression x[[1:2]] is not
> meaningful, as the elements
> >> of the list may be of different type, with no way
> to concatenate them.
> >
> > That's the wrong explanation:  the expression
> x[[1:2]] is meaningful,
> > but it means the same thing as x[[1]][[2]], not
> > c(x[[1]], x[[2]]).
> 
> Thank you for the clarification; I stand corrected.
> ___
> Patrick Breheny
> Assistant Professor
> Department of Biostatistics
> Department of Statistics
> University of Kentucky
>

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


Re: [R] Recursive Indexing Failed

2011-05-09 Thread Patrick Breheny

On 05/09/2011 09:52 AM, Duncan Murdoch wrote:

In general, the expression x[[1:2]] is not meaningful, as the elements
of the list may be of different type, with no way to concatenate them.


That's the wrong explanation:  the expression x[[1:2]] is meaningful,
but it means the same thing as x[[1]][[2]], not
c(x[[1]], x[[2]]).


Thank you for the clarification; I stand corrected.
___
Patrick Breheny
Assistant Professor
Department of Biostatistics
Department of Statistics
University of Kentucky

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


Re: [R] Recursive Indexing Failed

2011-05-09 Thread Duncan Murdoch

On 09/05/2011 9:18 AM, Patrick Breheny wrote:

On 05/09/2011 08:58 AM, Alaios wrote:
>  Dear all,
>  I would like to ask your help concerning an error message I get.
>
>  I have the following struct
>
>  str(CRagentInTime[[1]])
>  List of 2
>$ timelag: int 0
>$ CRagent:List of 50
> ..$ :List of 3
> .. ..$ CRmap: num [1:256, 1:256] NA NA NA NA NA NA NA NA NA NA ...
> .. ..$ xy   : num [1:2] 10 177
> .. ..$ sr   : num [1:49] -94.9 -92.8 -79.5 -97.6 -78.4 ...
>
>  and I wanted to select all the sr fields for every of each one of the 50 
CRagent Lists I have.
>
>  So I tried something like
>
>  str(CRagentInTime[[1]][[2]][[1:10]]$sr) and I get a message that
>  Error in CRagentInTime[[1]][[2]][[1:10]] :
> recursive indexing failed at level 3

Selecting multiple elements of a list using an expression like [[1:10]]
does not work.  For example:

x<- list("a","b")
x[[1:2]]

produces

Error in x[[1:2]] : subscript out of bounds

In general, the expression x[[1:2]] is not meaningful, as the elements
of the list may be of different type, with no way to concatenate them.


That's the wrong explanation:  the expression x[[1:2]] is meaningful, 
but it means the same thing as x[[1]][[2]], not

c(x[[1]], x[[2]]).

Duncan Murdoch

>
>  strange to me is that this one works
>
>  str(CRagentInTime[[1]][[2]][[1]]$sr)
>num [1:49] -106 -92.9 -101.3 -81.9 -96.7 ...
>
>
>  I would like to thank you in advance for your help
>  Best Regards
>  Alex
>
___
Patrick Breheny
Assistant Professor
Department of Biostatistics
Department of Statistics
University of Kentucky

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

2011-05-09 Thread Patrick Breheny

On 05/09/2011 09:24 AM, Alaios wrote:

So the only thing that might work is a for..loop to collect all these together?

Best REgards
Alex



You could also use sapply:

x <- list(list(One="a",Two=c("b","c")),list(One="d",Two=c("e","f")))

sapply(x,'[[',"Two")
 [,1] [,2]
[1,] "b"  "e"
[2,] "c"  "f"

In your example, it seems

sapply(CRagentInTime[[1]][[2]],'[[',"sr")

would work, but I am not in a position to replicate your code, as is it 
not self-contained.


___
Patrick Breheny
Assistant Professor
Department of Biostatistics
Department of Statistics
University of Kentucky



--- On Mon, 5/9/11, Patrick Breheny  wrote:


From: Patrick Breheny
Subject: Re: [R] Recursive Indexing Failed
To: "Alaios"
Cc: "R-help@r-project.org"
Date: Monday, May 9, 2011, 2:18 PM
On 05/09/2011 08:58 AM, Alaios
wrote:

Dear all,
I would like to ask your help concerning an error

message I get.


I have the following struct

str(CRagentInTime[[1]])
List of 2
$ timelag: int 0
$ CRagent:List of 50
 ..$ :List of 3
 .. ..$ CRmap: num [1:256, 1:256] NA NA NA

NA NA NA NA NA NA NA ...

 .. ..$ xy   : num [1:2] 10

177

 .. ..$ sr   : num [1:49]

-94.9 -92.8 -79.5 -97.6 -78.4 ...


and I wanted to select all the sr fields for every of

each one of the 50 CRagent Lists I have.


So I tried something like

str(CRagentInTime[[1]][[2]][[1:10]]$sr) and I get a

message that

Error in CRagentInTime[[1]][[2]][[1:10]] :
 recursive indexing failed at level 3


Selecting multiple elements of a list using an expression
like [[1:10]]
does not work.  For example:

x<- list("a","b")
x[[1:2]]

produces

Error in x[[1:2]] : subscript out of bounds

In general, the expression x[[1:2]] is not meaningful, as
the elements
of the list may be of different type, with no way to
concatenate them.



strange to me is that this one works

str(CRagentInTime[[1]][[2]][[1]]$sr)
num [1:49] -106 -92.9 -101.3 -81.9

-96.7 ...



I would like to thank you in advance for your help
Best Regards
Alex


___
Patrick Breheny
Assistant Professor
Department of Biostatistics
Department of Statistics
University of Kentucky



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

2011-05-09 Thread Pavan G
Hello All,
Let's say I have points on a x-y plane. x ranges from 0-2 and y from 0-2.
There are points in quadrants x[0:1]---y[0:1] and in x[1:2]y[1:2]. I
would like to get the mean and std of the points in the x[0:1]y[0:1]
quadrant alone. Is there a straight forward way to do it?

I asked a similar question a few days ago regarding plotting a subset of
data using conditions. The solution was:
http://r.789695.n4.nabble.com/Conditional-plot-length-in-R-td3503855.html

Thank you,
Why-so-serious.

[[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] Recursive Indexing Failed

2011-05-09 Thread peter dalgaard

On May 9, 2011, at 15:24 , Alaios wrote:

> So the only thing that might work is a for..loop to collect all these 
> together?

An implicit loop using lapply/sapply might be more like it:

lapply(CRagentInTime[[1]]$CRagent[1:10], "[[", "sr")

Notice that fancy indexing usually requires "[", not "[[".

> 
> Best REgards
> Alex
> 
> --- On Mon, 5/9/11, Patrick Breheny  wrote:
> 
>> From: Patrick Breheny 
>> Subject: Re: [R] Recursive Indexing Failed
>> To: "Alaios" 
>> Cc: "R-help@r-project.org" 
>> Date: Monday, May 9, 2011, 2:18 PM
>> On 05/09/2011 08:58 AM, Alaios
>> wrote:
>>> Dear all,
>>> I would like to ask your help concerning an error
>> message I get.
>>> 
>>> I have the following struct
>>> 
>>> str(CRagentInTime[[1]])
>>> List of 2
>>>$ timelag: int 0
>>>$ CRagent:List of 50
>>> ..$ :List of 3
>>> .. ..$ CRmap: num [1:256, 1:256] NA NA NA
>> NA NA NA NA NA NA NA ...
>>> .. ..$ xy   : num [1:2] 10
>> 177
>>> .. ..$ sr   : num [1:49]
>> -94.9 -92.8 -79.5 -97.6 -78.4 ...
>>> 
>>> and I wanted to select all the sr fields for every of
>> each one of the 50 CRagent Lists I have.
>>> 
>>> So I tried something like
>>> 
>>> str(CRagentInTime[[1]][[2]][[1:10]]$sr) and I get a
>> message that
>>> Error in CRagentInTime[[1]][[2]][[1:10]] :
>>> recursive indexing failed at level 3
>> 
>> Selecting multiple elements of a list using an expression
>> like [[1:10]] 
>> does not work.  For example:
>> 
>> x <- list("a","b")
>> x[[1:2]]
>> 
>> produces
>> 
>> Error in x[[1:2]] : subscript out of bounds
>> 
>> In general, the expression x[[1:2]] is not meaningful, as
>> the elements 
>> of the list may be of different type, with no way to
>> concatenate them.
>> 
>>> 
>>> strange to me is that this one works
>>> 
>>> str(CRagentInTime[[1]][[2]][[1]]$sr)
>>>num [1:49] -106 -92.9 -101.3 -81.9
>> -96.7 ...
>>> 
>>> 
>>> I would like to thank you in advance for your help
>>> Best Regards
>>> Alex
>>> 
>> ___
>> Patrick Breheny
>> Assistant Professor
>> Department of Biostatistics
>> Department of Statistics
>> University of Kentucky
>> 
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@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.


Re: [R] Recursive Indexing Failed

2011-05-09 Thread Alaios
So the only thing that might work is a for..loop to collect all these together?

Best REgards
Alex

--- On Mon, 5/9/11, Patrick Breheny  wrote:

> From: Patrick Breheny 
> Subject: Re: [R] Recursive Indexing Failed
> To: "Alaios" 
> Cc: "R-help@r-project.org" 
> Date: Monday, May 9, 2011, 2:18 PM
> On 05/09/2011 08:58 AM, Alaios
> wrote:
> > Dear all,
> > I would like to ask your help concerning an error
> message I get.
> >
> > I have the following struct
> >
> > str(CRagentInTime[[1]])
> > List of 2
> >   $ timelag: int 0
> >   $ CRagent:List of 50
> >    ..$ :List of 3
> >    .. ..$ CRmap: num [1:256, 1:256] NA NA NA
> NA NA NA NA NA NA NA ...
> >    .. ..$ xy   : num [1:2] 10
> 177
> >    .. ..$ sr   : num [1:49]
> -94.9 -92.8 -79.5 -97.6 -78.4 ...
> >
> > and I wanted to select all the sr fields for every of
> each one of the 50 CRagent Lists I have.
> >
> > So I tried something like
> >
> > str(CRagentInTime[[1]][[2]][[1:10]]$sr) and I get a
> message that
> > Error in CRagentInTime[[1]][[2]][[1:10]] :
> >    recursive indexing failed at level 3
> 
> Selecting multiple elements of a list using an expression
> like [[1:10]] 
> does not work.  For example:
> 
> x <- list("a","b")
> x[[1:2]]
> 
> produces
> 
> Error in x[[1:2]] : subscript out of bounds
> 
> In general, the expression x[[1:2]] is not meaningful, as
> the elements 
> of the list may be of different type, with no way to
> concatenate them.
> 
> >
> > strange to me is that this one works
> >
> > str(CRagentInTime[[1]][[2]][[1]]$sr)
> >   num [1:49] -106 -92.9 -101.3 -81.9
> -96.7 ...
> >
> >
> > I would like to thank you in advance for your help
> > Best Regards
> > Alex
> >
> ___
> Patrick Breheny
> Assistant Professor
> Department of Biostatistics
> Department of Statistics
> University of Kentucky
>

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


Re: [R] Recursive Indexing Failed

2011-05-09 Thread Patrick Breheny

On 05/09/2011 08:58 AM, Alaios wrote:

Dear all,
I would like to ask your help concerning an error message I get.

I have the following struct

str(CRagentInTime[[1]])
List of 2
  $ timelag: int 0
  $ CRagent:List of 50
   ..$ :List of 3
   .. ..$ CRmap: num [1:256, 1:256] NA NA NA NA NA NA NA NA NA NA ...
   .. ..$ xy   : num [1:2] 10 177
   .. ..$ sr   : num [1:49] -94.9 -92.8 -79.5 -97.6 -78.4 ...

and I wanted to select all the sr fields for every of each one of the 50 
CRagent Lists I have.

So I tried something like

str(CRagentInTime[[1]][[2]][[1:10]]$sr) and I get a message that
Error in CRagentInTime[[1]][[2]][[1:10]] :
   recursive indexing failed at level 3


Selecting multiple elements of a list using an expression like [[1:10]] 
does not work.  For example:


x <- list("a","b")
x[[1:2]]

produces

Error in x[[1:2]] : subscript out of bounds

In general, the expression x[[1:2]] is not meaningful, as the elements 
of the list may be of different type, with no way to concatenate them.




strange to me is that this one works

str(CRagentInTime[[1]][[2]][[1]]$sr)
  num [1:49] -106 -92.9 -101.3 -81.9 -96.7 ...


I would like to thank you in advance for your help
Best Regards
Alex


___
Patrick Breheny
Assistant Professor
Department of Biostatistics
Department of Statistics
University of Kentucky

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


Re: [R] Weighted box or violin plots in Lattice?

2011-05-09 Thread Deepayan Sarkar
On Mon, May 9, 2011 at 5:42 PM, David Winsemius  wrote:
>
> On May 9, 2011, at 12:35 AM, Deepayan Sarkar wrote:
>
>> On Mon, May 9, 2011 at 2:20 AM, Thomas Lumley  wrote:
>>>
>>> On Mon, May 9, 2011 at 6:35 AM, Deepayan Sarkar
>>>  wrote:

 On Sat, May 7, 2011 at 1:55 AM, Raphael Mazor 
 wrote:
>
> Is it possible to create weighted boxplots or violin plots in lattice?
>
> It seems that you can specify weights for panel.histogram() and
> panel.densityplot(), but not for panel.bwplot or panel.violin().

 Not for panel.histogram() either.

 It's not immediately obvious how you would get weighted boxplots.
>>>
>>> The way the survey world does it is to get weighted quantiles and work
>>> from them, as in survey:::svyboxplot().  The only tricky decision is
>>> what to do with outliers, since I haven't been able to think of any
>>> good way of indicating weights on them.
>>
>> So I guess with bwplot() one would have to write a version of
>> boxplot.stats() that uses weighted quantiles, and then write a
>> modified panel function.
>>
>> A crude approximation (if the weights don't vary too much) may be to
>> scale and round the weights to integers, and then repeat each data
>> point; e.g., newx <- rep(x, w), etc.
>
> You could do a bit better if you just substituted wtd.quantile from Hmisc
> with an x and weights argument for the fivenum call in boxplot.stats.

Thanks for that pointer. Incorporating weights into panel.bwplot()
would still be a bit painful though (more so than panel.violin).

-Deepayan

>
> require(Hmisc)
>> ?wtd.quantile
>> fivenum(x=1:10)
> [1]  1.0  3.0  5.5  8.0 10.0
>> wtd.quantile(x=1:10)
>   0%   25%   50%   75%  100%
>  1.00  3.25  5.50  7.75 10.00
>> wtd.quantile( x = 1:10, weights = 1:10)
>  0%  25%  50%  75% 100%
>   1    5    7    9   10
>
>  (Most people think the hinges are at the 25th and 75th percentiles anyway.)
>
>
>>
>> -Deepayan
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> David Winsemius, MD
> West Hartford, CT
>
>

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


[R] Recursive Indexing Failed

2011-05-09 Thread Alaios
Dear all,
I would like to ask your help concerning an error message I get.

I have the following struct

str(CRagentInTime[[1]])
List of 2
 $ timelag: int 0
 $ CRagent:List of 50
  ..$ :List of 3
  .. ..$ CRmap: num [1:256, 1:256] NA NA NA NA NA NA NA NA NA NA ...
  .. ..$ xy   : num [1:2] 10 177
  .. ..$ sr   : num [1:49] -94.9 -92.8 -79.5 -97.6 -78.4 ...

and I wanted to select all the sr fields for every of each one of the 50 
CRagent Lists I have.

So I tried something like

str(CRagentInTime[[1]][[2]][[1:10]]$sr) and I get a message that
Error in CRagentInTime[[1]][[2]][[1:10]] : 
  recursive indexing failed at level 3



strange to me is that this one works

str(CRagentInTime[[1]][[2]][[1]]$sr)
 num [1:49] -106 -92.9 -101.3 -81.9 -96.7 ...


I would like to thank you in advance for your help
Best Regards
Alex

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


Re: [R] maximum likelihood convergence reproducing Anderson Blundell 1982 Econometrica R vs Stata

2011-05-09 Thread peter dalgaard

On May 9, 2011, at 13:40 , Alex Olssen wrote:

> Hi Mike,
> 
> Mike said
> "is this it, page 1559?"
> 
> That is the front page yes, page 15*6*9 has the table, of which the
> model labelled 18s is the one I replicated.
> 

However, the R code you posted will at best replicate model 18. For 18s, you 
need to impose symmetry conditions.

The fit of model 18 does seem to give similar results to those in Table II, but 
not exactly. 

Even more puzzling, if you start from the published coefficients, nlm seems to 
be getting stuck at a non-concave point of the negative likelihood.


> nlm(p=ab, f=lnl, hessian=TRUE, y1=y1, y2=y2,
+ x1=x1, x2=x2, x3=x3, gradtol=1e-15)
$minimum
[1] -76.60681

$estimate
[1] -0.64701504  0.27284992 -0.13713084 -0.07205753  1.28200342 -0.24596766  
0.13502787  0.06001181

$gradient
[1]   2.782425  12.648629  -1.830244 -29.296795  -2.577734  -4.954042   
1.495517  11.016190

$hessian
  [,1] [,2] [,3]  [,4]  [,5] [,6] [,7] [,8]
[1,]  197435.9  1977197  1741724  805132.7  135821.9  1358013  1196714   553746
[2,] 1977197.4 19712076 17383474 8064540.2 1359856.0 13527720 11935305  5544903
[3,] 1741724.0 17383474 15336008 7121047.7 1197868.5 11929667 10529439  4896008
[4,]  805132.7  8064540  7121048 3315377.8  553733.1  5534923  4889523  2279404
[5,]  135821.9  1359856  1197868  553733.1  271511.7  2713733  2391332  1106572
[6,] 1358012.7 13527720 11929667 5534923.0 2713732.9 26955636 23784039 11054174
[7,] 1196714.3 11935305 10529439 4889522.6 2391331.9 23784039 20993413  9765022
[8,]  553746.0  5544903  4896008 2279404.1 1106571.9 11054174  9765022  4552693

$code
[1] 2

$iterations
[1] 4


-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@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.


Re: [R] rquest for help

2011-05-09 Thread Martin Morgan

On 05/09/2011 01:19 AM, Pawan Kakchingtabam wrote:


Sir,
Kindlly Guide me how to get the R CELFILES. I have install R but I cannat asses 
the command:
Data<- ReadAffy()
  and I got the error:
Error in AllButCelsForReadAffy(..., filenames = filenames, widget = widget,  :
   No cel filennames specified and no cel files in specified 
directory:C:/Documents and Settings/pawan.k/Desktop.


Pawan -- please ask questions about Bioconductor packages on the 
Bioconductor mailing list.


http://bioconductor.org/help/mailing-list/

Consult the help page for ReadAffy, ?ReadAffy, and setwd() to the 
directory containing the CEL files.


Martin


Wit regds,
Pawan



This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely 
for the use of the addressee(s). If you are not the intended recipient, please 
notify the sender by e-mail and delete the original message. Further, you are 
not to copy, disclose, or distribute this e-mail or its contents to any other 
person and any such actions that are unlawful. This e-mail may contain viruses. 
Ocimum Biosolutions has taken every reasonable precaution to minimize this 
risk, but is not liable for any damage you may sustain as a result of any virus 
in this e-mail. You should carry out your own virus checks before opening the 
e-mail or attachment.


The information contained in this email and any attachments is confidential and 
may be subject to copyright or other intellectual property protection. If you 
are not the intended recipient, you are not authorized to use or disclose this 
information, and we request that you notify us by reply mail or telephone and 
delete the original message from your mail system.

OCIMUMBIO SOLUTIONS (P) LTD
[[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.



--
Computational Biology
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109

Location: M1-B861
Telephone: 206 667-2793

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


Re: [R] coxph and survfit issue - strata

2011-05-09 Thread Terry Therneau
> Dear users,
>
> In a study with recurrent events:
> My objective is to get estimates of survival (obtained through a Cox  
> model) by rank of recurrence and by treatment group.
> With the following code (corresponding to a model with a global  
> effect of the treatment=rx), I get no error and manage to obtain  
> what I want :
> data<-(bladder)
> model1<-coxph(Surv(stop,event)~rx+strata(enum) 
> +cluster(id),data=bladder)
> data1<-data.frame(rx=1)
> survfit(model1,newdata=data1)
>
> But with the model with strata by treatment interaction  
> (corresponding to a model with an effect of the treatment by rank),  
> I get the following error:
> model2<-coxph(Surv(stop,event)~rx*strata(enum) 
> +cluster(id),data=bladder)
>
> data1<-data.frame(rx=1)
>
> survfit(model2,newdata=data1)
> Erreur dans strata(enum) : objet "enum" non trouv? =>error in  
> strata(enum) : object "enum" not found

 You have neglected to tell us what version of R and of the survival
library you are using.  (As the author, I always have the newest version
of course.)

  The example you gave works if there is no "cluster" statement.  Your
error is a surprise to me and I will look into it.

 Terry Therneau

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


[R] Mixed-design ANOVA: 2 between-subject factors and 1 within-subject factor

2011-05-09 Thread Floating0914
Dear all,

I am trying to using a mixed-design ANOVA to analyze my data. I have two
between subject variables: location (2 different locations) and age group
(young and old), and one within-subject variable: valence (positive,
neutral, negative).

I am looking at an Stevens(one between, two within) in Notes on the use of R
for psychology experiments and questionnaires (P34 in this article). 

In Stevens' example, he first create a matrix and put the data in a
multivariate format using cbind.data.frame() function.

Ela.mat <- matrix (c(19,.28), nrow=16, byrow=T)
Ela.mul <- cbind.data.frame(subj=1:16, gp=factor(rep(1:2,rep(8,2))),
Ela.mat)
dimnames(Ela.mul)[[2]] <-
c("subj","gp","d11","d12","d13","d21","d22","d23")

My data includes 447 data points:

5,4,5,
2,1,4,
4,7,8,
0,4,5,
3,1,7,
1,4,2,
3,2,5,
2,5,6,
4,2,6,
..
The three columns are positive, neutral and negative. First 31 rows are 
Young* location 1, next 39  Old* location1, next 43 Young* location2, and
the final 36 Old *location2.

I have 2 grouping variables and thus 4 uneven groups. Any suggestion for how
I can group them in cbind.data.frame()?

Or is there any suggestion for how to analyze in this 3 (valence: positive,
negative, neutral) X 2 (age: young vs. old) X 2 (location: a vs. b) mixed
Analysis of Variance (ANOVA)?

Thank you very much. Any and all help will be immensely appreciated.


--
View this message in context: 
http://r.789695.n4.nabble.com/Mixed-design-ANOVA-2-between-subject-factors-and-1-within-subject-factor-tp3508819p3508819.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] rquest for help

2011-05-09 Thread Pawan Kakchingtabam

Sir,
Kindlly Guide me how to get the R CELFILES. I have install R but I cannat asses 
the command:
Data <- ReadAffy()
 and I got the error:
Error in AllButCelsForReadAffy(..., filenames = filenames, widget = widget,  :
  No cel filennames specified and no cel files in specified 
directory:C:/Documents and Settings/pawan.k/Desktop.

Wit regds,
Pawan



This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely 
for the use of the addressee(s). If you are not the intended recipient, please 
notify the sender by e-mail and delete the original message. Further, you are 
not to copy, disclose, or distribute this e-mail or its contents to any other 
person and any such actions that are unlawful. This e-mail may contain viruses. 
Ocimum Biosolutions has taken every reasonable precaution to minimize this 
risk, but is not liable for any damage you may sustain as a result of any virus 
in this e-mail. You should carry out your own virus checks before opening the 
e-mail or attachment.


The information contained in this email and any attachments is confidential and 
may be subject to copyright or other intellectual property protection. If you 
are not the intended recipient, you are not authorized to use or disclose this 
information, and we request that you notify us by reply mail or telephone and 
delete the original message from your mail system.

OCIMUMBIO SOLUTIONS (P) LTD
[[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] maximum likelihood convergence reproducing Anderson Blundell 1982 Econometrica R vs Stata

2011-05-09 Thread Mike Marchywka







> Date: Mon, 9 May 2011 22:06:38 +1200
> From: alex.ols...@gmail.com
> To: pda...@gmail.com
> CC: r-help@r-project.org; da...@otter-rsch.com
> Subject: Re: [R] maximum likelihood convergence reproducing Anderson Blundell 
> 1982 Econometrica R vs Stata
>
> Peter said
>
> "Ahem! You might get us interested in your problem, but not to the
> level that we are going to install Stata and Tsp and actually dig out
> and study the scientific paper you are talking about. Please cite the
> results and explain the differences."
>
> Apologies Peter, will do,
>
> The results which I can emulate in Stata but not (yet) in R are reported 
> below.

did you actually cut/paste code anywhere and is your first coefficient -.19 or 
-.019?
Presumably typos would be one possible problem. 

> They come from Econometrica Vol. 50, No. 6 (Nov., 1982), pp. 1569


is this it, page 1559?

http://www.jstor.org/pss/1913396

generally it helps if we could at least see the equations to check your
code against typos ( note page number ?) in lnl that may fix part of the
mystery.  Is full text available
on author's site, doesn't come up on citeseer AFAICT,


http://citeseerx.ist.psu.edu/search?q=blundell+1982&sort=ascdate

I guess one question would be " what is beta" in lnl supposed to be -
it isn't used anywhere but I will also mentioned I'm not that familiar
with the R code ( I'm trying to work through this to learn R and the 
optimizers). 

maybe some words would help, is sigma supposed to be 2x2 or 8x8 and what are
e1 and e2 supposed to be?




>
> TABLE II - model 18s
>
> coef std err
> p10 -0.19 0.078
> p11 0.220 0.019
> p12 -0.148 0.021
> p13 -0.072
> p20 0.893 0.072
> p21 -0.148
> p22 0.050 0.035
> p23 0.098
>
> The results which I produced in Stata are reported below.
> I spent the last hour rewriting the code to reproduce this - since I
> am now at home and not at work :(
> My results are "identical" to those published. The estimates are for
> a 3 equation symmetrical singular system.
> I have not bothered to report symmetrical results and have backed out
> an extra estimate using adding up constraints.
> I have also backed out all standard errors using the delta method.
>
> . ereturn display
> --
> | Coef. Std. Err. z P>|z| [95% Conf. Interval]
> -+
> a |
> a1 | -.0188115 .0767759 -0.25 0.806 -.1692895 .1316664
> a2 | .8926598 .0704068 12.68 0.000 .7546651 1.030655
> a3 | .1261517 .0590193 2.14 0.033 .010476 .2418275
> -+
> g |
> g11 | .2199442 .0184075 11.95 0.000 .183866 .2560223
> g12 | -.1476856 .0211982 -6.97 0.000 -.1892334 -.1061378
> g13 | -.0722586 .0145154 -4.98 0.000 -.1007082 -.0438089
> g22 | .0496865 .0348052 1.43 0.153 -.0185305 .1179034
> g23 | .0979991 .0174397 5.62 0.000 .0638179 .1321803
> g33 | -.0257405 .0113869 -2.26 0.024 -.0480584 -.0034226
> --
>
> In R I cannot get results like this - I think it is probably to do
> with my inability at using the optimisers well.
> Any pointers would be appreciated.
>
> Peter said "Are we maximizing over the same parameter space? You say
> that the estimates from the paper gives a log-likelihood of 54.04, but
> the exact solution clocked in at 76.74, which in my book is rather
> larger."
>
> I meant +54.04 > -76.74. It is quite common to get positive
> log-likelihoods in these system estimation.
>
> Kind regards,
>
> Alex
>
> On 9 May 2011 19:04, peter dalgaard  wrote:
> >
> > On May 9, 2011, at 06:07 , Alex Olssen wrote:
> >
> >> Thank you all for your input.
> >>
> >> Unfortunately my problem is not yet resolved.  Before I respond to
> >> individual comments I make a clarification:
> >>
> >> In Stata, using the same likelihood function as above, I can reproduce
> >> EXACTLY (to 3 decimal places or more, which is exactly considering I
> >> am using different software) the results from model 8 of the paper.
> >>
> >> I take this as an indication that I am using the same likelihood
> >> function as the authors, and that it does indeed work.
> >> The reason I am trying to estimate the model in R is because while
> >> Stata reproduces model 8 perfectly it has convergence
> >> difficulties for some of the other models.
> >>
> >> Peter Dalgaard,
> >>
> >> "Better starting values would help. In this case, almost too good
> >> values are available:
> >>
> >> start <- c(coef(lm(y1~x1+x2+x3)), coef(lm(y2~x1+x2+x3)))
> >>
> >> which appears to be the _exact_ solution."
> >>
> >> Thanks for the suggestion.  Using these starting values produces the
> >> exact estimate that Dave Fournier emailed me.
> >> If these are the exact solution then why did the author publish
> >> different answers which are completely reproducible in
> >> Stata and 

Re: [R] Hosmer-Lemeshow 'goodness of fit'

2011-05-09 Thread Frank Harrell
The test in the rms package's residuals.lrm function is the le Cessie - van
Houwelingen - Copas - Hosmer unweighted sum of squares test for global
goodness of fit.  Like all statistical tests, a large P-value has no
information other than there was not sufficient evidence to reject the null
hypothesis.  Here the null hypothesis is that the true probabilities are
those specified by the model.  Such an omnibus test, though having good
general power (better than Hosmer-Lemeshow) lacks power to detect specific
alternatives.  That's why I spend more time allowing for nonlinearity of
predictors.

Frank


viostorm wrote:
> 
> Again, thanks so much for your help.
> 
> Is there a "for dummies" version for interpreting the le Cessie and
> Houwelingen test.  I read the 1991 biometrics paper but honestly got lost
> in the math.
> 
> Is it interpreted the same way the Hosmer-Lemeshow test is?  ie, a
> non-significant result means model fits well.   
> 
> I guess what does, what would my p-value of p=0.284362 tell you about my
> model?  
> 
> I would like to describe the goodness of fit of my model in a paper but
> I'm worried the average medical reader would not know how to interpret the
> result of this test whereas there are lots of references on interpreting
> Hosmer-Lemeshow.
> 
> (my cross validated c-statistic was 0.69 and r^2 was 0.15)
> 
> Thanks again for your all help! (also with my k-fold crossvalidation
> question!)
> 
> -Rob
> 
>  
> Robert Schutt, MD, MCS 
> Resident - Department of Internal Medicine 
> University of Virginia, Charlottesville, Virginia
> 


-
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: 
http://r.789695.n4.nabble.com/Hosmer-Lemeshow-goodness-of-fit-tp3508127p3509102.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] Weighted box or violin plots in Lattice?

2011-05-09 Thread David Winsemius


On May 9, 2011, at 12:35 AM, Deepayan Sarkar wrote:


On Mon, May 9, 2011 at 2:20 AM, Thomas Lumley  wrote:

On Mon, May 9, 2011 at 6:35 AM, Deepayan Sarkar
 wrote:
On Sat, May 7, 2011 at 1:55 AM, Raphael Mazor  
 wrote:
Is it possible to create weighted boxplots or violin plots in  
lattice?


It seems that you can specify weights for panel.histogram() and
panel.densityplot(), but not for panel.bwplot or panel.violin().


Not for panel.histogram() either.

It's not immediately obvious how you would get weighted boxplots.


The way the survey world does it is to get weighted quantiles and  
work

from them, as in survey:::svyboxplot().  The only tricky decision is
what to do with outliers, since I haven't been able to think of any
good way of indicating weights on them.


So I guess with bwplot() one would have to write a version of
boxplot.stats() that uses weighted quantiles, and then write a
modified panel function.

A crude approximation (if the weights don't vary too much) may be to
scale and round the weights to integers, and then repeat each data
point; e.g., newx <- rep(x, w), etc.


You could do a bit better if you just substituted wtd.quantile from  
Hmisc with an x and weights argument for the fivenum call in  
boxplot.stats.


require(Hmisc)
> ?wtd.quantile
> fivenum(x=1:10)
[1]  1.0  3.0  5.5  8.0 10.0
> wtd.quantile(x=1:10)
   0%   25%   50%   75%  100%
 1.00  3.25  5.50  7.75 10.00
> wtd.quantile( x = 1:10, weights = 1:10)
  0%  25%  50%  75% 100%
   1579   10

 (Most people think the hinges are at the 25th and 75th percentiles  
anyway.)





-Deepayan

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] Suppressing iterations in DEoptim

2011-05-09 Thread Uwe Ligges



On 09.05.2011 14:03, arnab.ma...@dc.ibm.com wrote:

Dear Uwe,

I already have gone through that document. But I could not find the
solution.


I tiold you that help page points us to the help page for
?DEoptim.control
and that one has an argument "trace".

Please read both, my original message as well as the help pages.

Uwe Ligges




Thanks&  Regards

Arnab Kumar Maity

|| IBM Global Process Services ||
|| 2nd Floor, VBC Solitaire ||
|| 47&  49, Bazullah Road || T Nagar ||
|| Chennai - 600017 || India ||
|| Email: arnab.ma...@dc.ibm.com ||
|| Ph: +91 8939390048 ||



  Uwe Ligges
  To
arnab.ma...@dc.ibm.com
  05/09/2011 05:29   cc
  PMr-help@r-project.org
Subject
Re: [R] Suppressing iterations in
DEoptim












On 09.05.2011 13:47, arnab.ma...@dc.ibm.com wrote:

Dear Uwe,

Which help file you are talking about?


The one you get when typing

?DEoptim

which one do you think is more appropriate for getting help on DEoptim ?

Uwe





Thanks&   Regards

Arnab Kumar Maity

|| IBM Global Process Services ||
|| 2nd Floor, VBC Solitaire ||
|| 47&   49, Bazullah Road || T Nagar ||
|| Chennai - 600017 || India ||
|| Email: arnab.ma...@dc.ibm.com ||
|| Ph: +91 8939390048 ||



   Uwe Ligges
   

To

 arnab.ma...@dc.ibm.com
   05/09/2011 04:24

cc

   PMr-help@r-project.org


Subject

 Re: [R] Suppressing iterations in
 DEoptim












On 09.05.2011 11:06, arnab.ma...@dc.ibm.com wrote:


Dear R users,

During the the running of DEoptim function which belongs to "DEoptim"
package it automatically gives the output like the following:

Iteration: 1 bestvalit: 181.379847 bestmemit:0.2264991.395852
Iteration: 2 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 3 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 4 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 5 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 6 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 7 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 8 bestvalit: 12.952513 bestmemit:2.7157097.691444
Iteration: 9 bestvalit: 3.254643 bestmemit:2.3901515.597838
Iteration: 10 bestvalit: 3.254643 bestmemit:2.3901515.597838
Iteration: 11 bestvalit: 1.820207 bestmemit:2.1707184.779070
Iteration: 12 bestvalit: 1.205168 bestmemit:1.8016293.320871
Iteration: 13 bestvalit: 1.101356 bestmemit:1.5871302.605967

Is their any procedure to suppress this i.e not to print this

information?

Yes, the procedure is to read the help file, as you have been asked by
the posting guide before posting.

?DEoptim points you to the help for ?DEoptim.control which has a trace
argument that seems to be useful ...

Uwe Ligges




Thank you for your kind reply.



Thanks&Regards

Arnab Kumar Maity

|| IBM Global Process Services ||
|| 2nd Floor, VBC Solitaire ||
|| 47&49, Bazullah Road || T Nagar ||
|| Chennai - 600017 || India ||
|| Email: arnab.ma...@dc.ibm.com ||
|| Ph: +91 8939390048 ||

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

2011-05-09 Thread arnab . maity
Dear Uwe,

I already have gone through that document. But I could not find the
solution.

Thanks & Regards

Arnab Kumar Maity

|| IBM Global Process Services ||
|| 2nd Floor, VBC Solitaire ||
|| 47 & 49, Bazullah Road || T Nagar ||
|| Chennai - 600017 || India ||
|| Email: arnab.ma...@dc.ibm.com ||
|| Ph: +91 8939390048 ||


   
 Uwe Ligges
To 
   arnab.ma...@dc.ibm.com  
 05/09/2011 05:29   cc 
 PMr-help@r-project.org
   Subject 
   Re: [R] Suppressing iterations in   
   DEoptim 
   
   
   
   
   
   






On 09.05.2011 13:47, arnab.ma...@dc.ibm.com wrote:
> Dear Uwe,
>
> Which help file you are talking about?

The one you get when typing

?DEoptim

which one do you think is more appropriate for getting help on DEoptim ?

Uwe



>
> Thanks&  Regards
>
> Arnab Kumar Maity
>
> || IBM Global Process Services ||
> || 2nd Floor, VBC Solitaire ||
> || 47&  49, Bazullah Road || T Nagar ||
> || Chennai - 600017 || India ||
> || Email: arnab.ma...@dc.ibm.com ||
> || Ph: +91 8939390048 ||
>
>
>
>   Uwe Ligges
>  .tu-dortmund.de>
To
> arnab.ma...@dc.ibm.com
>   05/09/2011 04:24
cc
>   PMr-help@r-project.org
>
Subject
> Re: [R] Suppressing iterations in
> DEoptim
>
>
>
>
>
>
>
>
>
>
>
>
> On 09.05.2011 11:06, arnab.ma...@dc.ibm.com wrote:
>>
>> Dear R users,
>>
>> During the the running of DEoptim function which belongs to "DEoptim"
>> package it automatically gives the output like the following:
>>
>> Iteration: 1 bestvalit: 181.379847 bestmemit:0.2264991.395852
>> Iteration: 2 bestvalit: 14.062649 bestmemit:2.2903575.597838
>> Iteration: 3 bestvalit: 14.062649 bestmemit:2.2903575.597838
>> Iteration: 4 bestvalit: 14.062649 bestmemit:2.2903575.597838
>> Iteration: 5 bestvalit: 14.062649 bestmemit:2.2903575.597838
>> Iteration: 6 bestvalit: 14.062649 bestmemit:2.2903575.597838
>> Iteration: 7 bestvalit: 14.062649 bestmemit:2.2903575.597838
>> Iteration: 8 bestvalit: 12.952513 bestmemit:2.7157097.691444
>> Iteration: 9 bestvalit: 3.254643 bestmemit:2.3901515.597838
>> Iteration: 10 bestvalit: 3.254643 bestmemit:2.3901515.597838
>> Iteration: 11 bestvalit: 1.820207 bestmemit:2.1707184.779070
>> Iteration: 12 bestvalit: 1.205168 bestmemit:1.8016293.320871
>> Iteration: 13 bestvalit: 1.101356 bestmemit:1.5871302.605967
>>
>> Is their any procedure to suppress this i.e not to print this
> information?
>
> Yes, the procedure is to read the help file, as you have been asked by
> the posting guide before posting.
>
> ?DEoptim points you to the help for ?DEoptim.control which has a trace
> argument that seems to be useful ...
>
> Uwe Ligges
>
>
>
>> Thank you for your kind reply.
>>
>>
>>
>> Thanks&   Regards
>>
>> Arnab Kumar Maity
>>
>> || IBM Global Process Services ||
>> || 2nd Floor, VBC Solitaire ||
>> || 47&   49, Bazullah Road || T Nagar ||
>> || Chennai - 600017 || India ||
>> || Email: arnab.ma...@dc.ibm.com ||
>> || Ph: +91 8939390048 ||
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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] Suppressing iterations in DEoptim

2011-05-09 Thread Uwe Ligges



On 09.05.2011 13:47, arnab.ma...@dc.ibm.com wrote:

Dear Uwe,

Which help file you are talking about?


The one you get when typing

?DEoptim

which one do you think is more appropriate for getting help on DEoptim ?

Uwe





Thanks&  Regards

Arnab Kumar Maity

|| IBM Global Process Services ||
|| 2nd Floor, VBC Solitaire ||
|| 47&  49, Bazullah Road || T Nagar ||
|| Chennai - 600017 || India ||
|| Email: arnab.ma...@dc.ibm.com ||
|| Ph: +91 8939390048 ||



  Uwe Ligges
  To
arnab.ma...@dc.ibm.com
  05/09/2011 04:24   cc
  PMr-help@r-project.org
Subject
Re: [R] Suppressing iterations in
DEoptim












On 09.05.2011 11:06, arnab.ma...@dc.ibm.com wrote:


Dear R users,

During the the running of DEoptim function which belongs to "DEoptim"
package it automatically gives the output like the following:

Iteration: 1 bestvalit: 181.379847 bestmemit:0.2264991.395852
Iteration: 2 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 3 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 4 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 5 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 6 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 7 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 8 bestvalit: 12.952513 bestmemit:2.7157097.691444
Iteration: 9 bestvalit: 3.254643 bestmemit:2.3901515.597838
Iteration: 10 bestvalit: 3.254643 bestmemit:2.3901515.597838
Iteration: 11 bestvalit: 1.820207 bestmemit:2.1707184.779070
Iteration: 12 bestvalit: 1.205168 bestmemit:1.8016293.320871
Iteration: 13 bestvalit: 1.101356 bestmemit:1.5871302.605967

Is their any procedure to suppress this i.e not to print this

information?

Yes, the procedure is to read the help file, as you have been asked by
the posting guide before posting.

?DEoptim points you to the help for ?DEoptim.control which has a trace
argument that seems to be useful ...

Uwe Ligges




Thank you for your kind reply.



Thanks&   Regards

Arnab Kumar Maity

|| IBM Global Process Services ||
|| 2nd Floor, VBC Solitaire ||
|| 47&   49, Bazullah Road || T Nagar ||
|| Chennai - 600017 || India ||
|| Email: arnab.ma...@dc.ibm.com ||
|| Ph: +91 8939390048 ||

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] converting a matrix or data.frame into an html table

2011-05-09 Thread David Scott

On 9/05/2011 10:40 p.m., Samuel Le wrote:

Dear all,



Is there a function in R to convert a matrix or a data.frame into an html table?

Many thanks,

Samuel



xtable() in the xtable package can do this (at least to some extent). It 
is commonly used to write LaTeX but there is an option to produce html 
as well.


David Scott

--
_
David Scott Department of Statistics
The University of Auckland, PB 92019
Auckland 1142,NEW ZEALAND
Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
Email:  d.sc...@auckland.ac.nz,  Fax: +64 9 373 7018

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


Re: [R] Suppressing iterations in DEoptim

2011-05-09 Thread arnab . maity
Dear Uwe,

Which help file you are talking about?


Thanks & Regards

Arnab Kumar Maity

|| IBM Global Process Services ||
|| 2nd Floor, VBC Solitaire ||
|| 47 & 49, Bazullah Road || T Nagar ||
|| Chennai - 600017 || India ||
|| Email: arnab.ma...@dc.ibm.com ||
|| Ph: +91 8939390048 ||


   
 Uwe Ligges
To 
   arnab.ma...@dc.ibm.com  
 05/09/2011 04:24   cc 
 PMr-help@r-project.org
   Subject 
   Re: [R] Suppressing iterations in   
   DEoptim 
   
   
   
   
   
   






On 09.05.2011 11:06, arnab.ma...@dc.ibm.com wrote:
>
> Dear R users,
>
> During the the running of DEoptim function which belongs to "DEoptim"
> package it automatically gives the output like the following:
>
> Iteration: 1 bestvalit: 181.379847 bestmemit:0.2264991.395852
> Iteration: 2 bestvalit: 14.062649 bestmemit:2.2903575.597838
> Iteration: 3 bestvalit: 14.062649 bestmemit:2.2903575.597838
> Iteration: 4 bestvalit: 14.062649 bestmemit:2.2903575.597838
> Iteration: 5 bestvalit: 14.062649 bestmemit:2.2903575.597838
> Iteration: 6 bestvalit: 14.062649 bestmemit:2.2903575.597838
> Iteration: 7 bestvalit: 14.062649 bestmemit:2.2903575.597838
> Iteration: 8 bestvalit: 12.952513 bestmemit:2.7157097.691444
> Iteration: 9 bestvalit: 3.254643 bestmemit:2.3901515.597838
> Iteration: 10 bestvalit: 3.254643 bestmemit:2.3901515.597838
> Iteration: 11 bestvalit: 1.820207 bestmemit:2.1707184.779070
> Iteration: 12 bestvalit: 1.205168 bestmemit:1.8016293.320871
> Iteration: 13 bestvalit: 1.101356 bestmemit:1.5871302.605967
>
> Is their any procedure to suppress this i.e not to print this
information?

Yes, the procedure is to read the help file, as you have been asked by
the posting guide before posting.

?DEoptim points you to the help for ?DEoptim.control which has a trace
argument that seems to be useful ...

Uwe Ligges



> Thank you for your kind reply.
>
>
>
> Thanks&  Regards
>
> Arnab Kumar Maity
>
> || IBM Global Process Services ||
> || 2nd Floor, VBC Solitaire ||
> || 47&  49, Bazullah Road || T Nagar ||
> || Chennai - 600017 || India ||
> || Email: arnab.ma...@dc.ibm.com ||
> || Ph: +91 8939390048 ||
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] maximum likelihood convergence reproducing Anderson Blundell 1982 Econometrica R vs Stata

2011-05-09 Thread Alex Olssen
Hi Mike,

Mike said
"is this it, page 1559?"

That is the front page yes, page 15*6*9 has the table, of which the
model labelled 18s is the one I replicated.

"did you actually cut/paste code anywhere and is your first
coefficient -.19 or -.019?
Presumably typos would be one possible problem."

-0.19 is not a typo, it is pi10 in the paper, and a1 in my Stata
estimation - as far as I can tell cutting and pasting is not the
problem.

"generally it helps if we could at least see the equations to check your
code against typos ( note page number ?) in lnl that may fix part of the
mystery.  Is full text available
on author's site, doesn't come up on citeseer AFAICT,"

Unfortunately I do not know of any place to get the full version of
this paper that doesn't require access to a database such as JSTOR.
The fact that this likelihood function reproduces the published
results in Stata makes me confident that it is correct - I also have
read a lot on systems estimation and it is a pretty standard
likelihood function.

"I guess one question would be " what is beta" in lnl supposed to be -
it isn't used anywhere but I will also mentioned I'm not that familiar
with the R code ( I'm trying to work through this to learn R and the
optimizers).

maybe some words would help, is sigma supposed to be 2x2 or 8x8 and what are
e1 and e2 supposed to be?"

The code above is certainly not as elegant as it could be - in this
case the beta is rather superfluous.  It is just a vector to hold
parameters - but since I called all the parameters theta anyway there
is no need for it.  e1 and e2 are the residuals from the first and
second equations of the system.  Sigma is a 2x2 matrix which is the
outer product of the two vectors of residuals.

Kind regards,

Alex



On 9 May 2011 23:12, Mike Marchywka  wrote:
>
>
>
>
>
>
> 
>> Date: Mon, 9 May 2011 22:06:38 +1200
>> From: alex.ols...@gmail.com
>> To: pda...@gmail.com
>> CC: r-help@r-project.org; da...@otter-rsch.com
>> Subject: Re: [R] maximum likelihood convergence reproducing Anderson 
>> Blundell 1982 Econometrica R vs Stata
>>
>> Peter said
>>
>> "Ahem! You might get us interested in your problem, but not to the
>> level that we are going to install Stata and Tsp and actually dig out
>> and study the scientific paper you are talking about. Please cite the
>> results and explain the differences."
>>
>> Apologies Peter, will do,
>>
>> The results which I can emulate in Stata but not (yet) in R are reported 
>> below.
>
> did you actually cut/paste code anywhere and is your first coefficient -.19 
> or -.019?
> Presumably typos would be one possible problem.
>
>> They come from Econometrica Vol. 50, No. 6 (Nov., 1982), pp. 1569
>
>
> is this it, page 1559?
>
> http://www.jstor.org/pss/1913396
>
> generally it helps if we could at least see the equations to check your
> code against typos ( note page number ?) in lnl that may fix part of the
> mystery.  Is full text available
> on author's site, doesn't come up on citeseer AFAICT,
>
>
> http://citeseerx.ist.psu.edu/search?q=blundell+1982&sort=ascdate
>
> I guess one question would be " what is beta" in lnl supposed to be -
> it isn't used anywhere but I will also mentioned I'm not that familiar
> with the R code ( I'm trying to work through this to learn R and the 
> optimizers).
>
> maybe some words would help, is sigma supposed to be 2x2 or 8x8 and what are
> e1 and e2 supposed to be?
>
>
>
>
>>
>> TABLE II - model 18s
>>
>> coef std err
>> p10 -0.19 0.078
>> p11 0.220 0.019
>> p12 -0.148 0.021
>> p13 -0.072
>> p20 0.893 0.072
>> p21 -0.148
>> p22 0.050 0.035
>> p23 0.098
>>
>> The results which I produced in Stata are reported below.
>> I spent the last hour rewriting the code to reproduce this - since I
>> am now at home and not at work :(
>> My results are "identical" to those published. The estimates are for
>> a 3 equation symmetrical singular system.
>> I have not bothered to report symmetrical results and have backed out
>> an extra estimate using adding up constraints.
>> I have also backed out all standard errors using the delta method.
>>
>> . ereturn display
>> --
>> | Coef. Std. Err. z P>|z| [95% Conf. Interval]
>> -+
>> a |
>> a1 | -.0188115 .0767759 -0.25 0.806 -.1692895 .1316664
>> a2 | .8926598 .0704068 12.68 0.000 .7546651 1.030655
>> a3 | .1261517 .0590193 2.14 0.033 .010476 .2418275
>> -+
>> g |
>> g11 | .2199442 .0184075 11.95 0.000 .183866 .2560223
>> g12 | -.1476856 .0211982 -6.97 0.000 -.1892334 -.1061378
>> g13 | -.0722586 .0145154 -4.98 0.000 -.1007082 -.0438089
>> g22 | .0496865 .0348052 1.43 0.153 -.0185305 .1179034
>> g23 | .0979991 .0174397 5.62 0.000 .0638179 .1321803
>> g33 | -.0257405 .0113869 -2.26 0.024 -.0480584 -.0034226
>> ---

Re: [R] converting a matrix or data.frame into an html table

2011-05-09 Thread Gregoire Pau

Have a look at hwrite() in the hwriter package:
http://www.embl.de/~gpau/hwriter/index.html

If x is a data frame, the following will do it:
> library("hwriter")
> hwrite(x, "x.html")

Cheers,

Greg
---
Gregoire Pau
EMBL Research Officer
http://www.embl.de/~gpau/

On 09/05/11 12:40, Samuel Le wrote:

Dear all,



Is there a function in R to convert a matrix or a data.frame into an html table?

Many thanks,

Samuel


[[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] package update

2011-05-09 Thread Uwe Ligges



On 08.05.2011 19:54, eric wrote:

I tried to update my packages using update.packages()

I got the following message:

The downloaded packages are in
‘/tmp/RtmpyDYdTX/downloaded_packages’
Warning in install.packages(update[instlib == l, "Package"], l, contriburl =
contriburl,  :
   'lib = "/usr/lib/R/library"' is not writable
Error in install.packages(update[instlib == l, "Package"], l, contriburl =
contriburl,  :
   unable to install package

How do I fix this ?


If you want to update packages in R's default library in 
/usr/lib/R/library, you will need root permissions.


Uwe Ligges





--
View this message in context: 
http://r.789695.n4.nabble.com/package-update-tp3507479p3507479.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] Suppressing iterations in DEoptim

2011-05-09 Thread Uwe Ligges



On 09.05.2011 11:06, arnab.ma...@dc.ibm.com wrote:


Dear R users,

During the the running of DEoptim function which belongs to "DEoptim"
package it automatically gives the output like the following:

Iteration: 1 bestvalit: 181.379847 bestmemit:0.2264991.395852
Iteration: 2 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 3 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 4 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 5 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 6 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 7 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 8 bestvalit: 12.952513 bestmemit:2.7157097.691444
Iteration: 9 bestvalit: 3.254643 bestmemit:2.3901515.597838
Iteration: 10 bestvalit: 3.254643 bestmemit:2.3901515.597838
Iteration: 11 bestvalit: 1.820207 bestmemit:2.1707184.779070
Iteration: 12 bestvalit: 1.205168 bestmemit:1.8016293.320871
Iteration: 13 bestvalit: 1.101356 bestmemit:1.5871302.605967

Is their any procedure to suppress this i.e not to print this information?


Yes, the procedure is to read the help file, as you have been asked by 
the posting guide before posting.


?DEoptim points you to the help for ?DEoptim.control which has a trace 
argument that seems to be useful ...


Uwe Ligges




Thank you for your kind reply.



Thanks&  Regards

Arnab Kumar Maity

|| IBM Global Process Services ||
|| 2nd Floor, VBC Solitaire ||
|| 47&  49, Bazullah Road || T Nagar ||
|| Chennai - 600017 || India ||
|| Email: arnab.ma...@dc.ibm.com ||
|| Ph: +91 8939390048 ||

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] converting a matrix or data.frame into an html table

2011-05-09 Thread Gerrit Eichner

Hello, Samuel,

take a look at the package R2HTML.

 Hth  --  Gerrit


On Mon, 9 May 2011, Samuel Le wrote:


Dear all,

Is there a function in R to convert a matrix or a data.frame into an html table?

Many thanks,

Samuel



-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

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


Re: [R] Alter a line in a file.

2011-05-09 Thread Patrick Connolly
On Thu, 05-May-2011 at 06:13AM -0700, Joel wrote:

|> 
|> jholtman wrote:
|> > 
|> > a <- readLines(textConnection('setting1="value1"
|> > setting2="value2"
|> > setting3="value3"
|> > setting4="value4"'))
|> > closeAllConnections()
|> > # change  values
|> > ac <- sub('setting4="value4"', 'setting4="value5"', a)
|> > writeLines(ac, con='myFile.txt')
|> > 
|> 
|> Problem is that I dont know the value on all the settings that I wanna
|> change otherwise that looks like something to continue on.
|> 
|> 
|> 
|> Petr Pikal wrote:
|> > 
|> > What file, what is its structure, is it some R object or separate file?
|> > What did you try and what went wrong?
|> > 
|> > Regards
|> > Petr 
|> > 
|> 
|> Just a normal textfile nothing fancy
|> Ive tried diffrent kind of ways of useing my OS witch is linux by
|> the system command to do it for me but Im not good enought on
|> regexp to get it to work properly.

R is great for lots of things.  I even use it for things that someone
more skilled would do using Perl, but in your case, it would be much
easier to use a text editor.  If you can't use Emacs or vi, use nano.
You don't need to know anything about text editors to use the menu
options it has for everything.

HTH

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___Patrick Connolly   
 {~._.~}   Great minds discuss ideas
 _( Y )_ Average minds discuss events 
(:_~*~_:)  Small minds discuss people  
 (_)-(_)  . Eleanor Roosevelt
  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] converting a matrix or data.frame into an html table

2011-05-09 Thread Samuel Le
Dear all,



Is there a function in R to convert a matrix or a data.frame into an html table?

Many thanks,

Samuel


[[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] maximum likelihood convergence reproducing Anderson Blundell 1982 Econometrica R vs Stata

2011-05-09 Thread Alex Olssen
Peter said

"Ahem! You might get us interested in your problem, but not to the
level that we are going to install Stata and Tsp and actually dig out
and study the scientific paper you are talking about. Please cite the
results and explain the differences."

Apologies Peter, will do,

The results which I can emulate in Stata but not (yet) in R are reported below.
They come from Econometrica Vol. 50, No. 6 (Nov., 1982), pp. 1569

TABLE II - model 18s

 coef std err
p10 -0.19 0.078
p11 0.2200.019
p12 -0.148   0.021
p13 -0.072
p20 0.8930.072
p21 -0.148
p22 0.0500.035
p23 0.098

The results which I produced in Stata are reported below.
I spent the last hour rewriting the code to reproduce this - since I
am now at home and not at work :(
My results are "identical" to those published.  The estimates are for
a 3 equation symmetrical singular system.
I have not bothered to report symmetrical results and have backed out
an extra estimate using adding up constraints.
I have also backed out all standard errors using the delta method.

. ereturn display
--
|  Coef.   Std. Err.  zP>|z| [95% Conf. Interval]
-+
a|
 a1 |  -.0188115   .0767759-0.25   0.806-.1692895.1316664
 a2 |   .8926598   .070406812.68   0.000 .75466511.030655
 a3 |   .1261517   .0590193 2.14   0.033  .010476.2418275
-+
g|
g11 |   .2199442   .018407511.95   0.000  .183866.2560223
g12 |  -.1476856   .0211982-6.97   0.000-.1892334   -.1061378
g13 |  -.0722586   .0145154-4.98   0.000-.1007082   -.0438089
g22 |   .0496865   .0348052 1.43   0.153-.0185305.1179034
g23 |   .0979991   .0174397 5.62   0.000 .0638179.1321803
g33 |  -.0257405   .0113869-2.26   0.024-.0480584   -.0034226
--

In R I cannot get results like this - I think it is probably to do
with my inability at using the optimisers well.
Any pointers would be appreciated.

Peter said "Are we maximizing over the same parameter space? You say
that the estimates from the paper gives a log-likelihood of 54.04, but
the exact solution clocked in at 76.74, which in my book is rather
larger."

I meant +54.04 > -76.74.  It is quite common to get positive
log-likelihoods in these system estimation.

Kind regards,

Alex

On 9 May 2011 19:04, peter dalgaard  wrote:
>
> On May 9, 2011, at 06:07 , Alex Olssen wrote:
>
>> Thank you all for your input.
>>
>> Unfortunately my problem is not yet resolved.  Before I respond to
>> individual comments I make a clarification:
>>
>> In Stata, using the same likelihood function as above, I can reproduce
>> EXACTLY (to 3 decimal places or more, which is exactly considering I
>> am using different software) the results from model 8 of the paper.
>>
>> I take this as an indication that I am using the same likelihood
>> function as the authors, and that it does indeed work.
>> The reason I am trying to estimate the model in R is because while
>> Stata reproduces model 8 perfectly it has convergence
>> difficulties for some of the other models.
>>
>> Peter Dalgaard,
>>
>> "Better starting values would help. In this case, almost too good
>> values are available:
>>
>> start <- c(coef(lm(y1~x1+x2+x3)), coef(lm(y2~x1+x2+x3)))
>>
>> which appears to be the _exact_ solution."
>>
>> Thanks for the suggestion.  Using these starting values produces the
>> exact estimate that Dave Fournier emailed me.
>> If these are the exact solution then why did the author publish
>> different answers which are completely reproducible in
>> Stata and Tsp?
>
>
> Ahem! You might get us interested in your problem, but not to the level that 
> we are going to install Stata and Tsp and actually dig out and study the 
> scientific paper you are talking about. Please cite the results and explain 
> the differences.
>
> Are we maximizing over the same parameter space? You say that the estimates 
> from the paper gives a log-likelihood of 54.04, but the exact solution 
> clocked in at 76.74, which in my book is rather larger.
>
> Confused
>
> -p
>
>
>>
>> Ravi,
>>
>> Thanks for introducing optimx to me, I am new to R.  I completely
>> agree that you can get higher log-likelihood values
>> than what those obtained with optim and the starting values suggested
>> by Peter.  In fact, in Stata, when I reproduce
>> the results of model 8 to more than 3 dp I get a log-likelihood of 54.039139.
>>
>> Furthermore if I estimate model 8 without symmetry imposed on the
>> system I reproduce the Likelihood Ratio reported
>> in the paper to 3 deci

[R] Rule based Classification

2011-05-09 Thread Denny
Dear R-help.

I am studying Dataming using R and I am going to make Rule Based
Classification's R code.
But I searched for Rule Based Classification throught Google, I have
failed to find out the package for R.
Would you recommend R some packages which can make Rule Based
Classification?


Best Regards,

Kyung Won Park

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

2011-05-09 Thread arnab . maity

Dear R users,

During the the running of DEoptim function which belongs to "DEoptim"
package it automatically gives the output like the following:

Iteration: 1 bestvalit: 181.379847 bestmemit:0.2264991.395852
Iteration: 2 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 3 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 4 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 5 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 6 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 7 bestvalit: 14.062649 bestmemit:2.2903575.597838
Iteration: 8 bestvalit: 12.952513 bestmemit:2.7157097.691444
Iteration: 9 bestvalit: 3.254643 bestmemit:2.3901515.597838
Iteration: 10 bestvalit: 3.254643 bestmemit:2.3901515.597838
Iteration: 11 bestvalit: 1.820207 bestmemit:2.1707184.779070
Iteration: 12 bestvalit: 1.205168 bestmemit:1.8016293.320871
Iteration: 13 bestvalit: 1.101356 bestmemit:1.5871302.605967

Is their any procedure to suppress this i.e not to print this information?

Thank you for your kind reply.



Thanks & Regards

Arnab Kumar Maity

|| IBM Global Process Services ||
|| 2nd Floor, VBC Solitaire ||
|| 47 & 49, Bazullah Road || T Nagar ||
|| Chennai - 600017 || India ||
|| Email: arnab.ma...@dc.ibm.com ||
|| Ph: +91 8939390048 ||

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


Re: [R] Summarising by group

2011-05-09 Thread peter dalgaard

On May 9, 2011, at 11:12 , Martyn Byng wrote:

> I wonder if someone with more experience than me on using R to summarise
> by group wants to post a reply to this 

Not really (but how did those people manage to overlook by()?). However, 
another matter

PLEASE DO NOT BE SO B***DY LAZY AND START A NEW TOPIC AS A REPLY TO SOMETHING 
COMPLETELY UNRELATED. 

Those of us with threading mail clients, will see your post as part of the 
thread 

"maximum likelihood convergence reproducing Anderson Blundell 1982 Econometrica 
R vs Stata"

and, at least with Mac OSX's Mail, the header of the entire thread is now 
"Summarising by group".

Peter D.


> 
> http://www.analyticbridge.com/group/sasandstatisticalprogramming/forum/t
> opics/why-still-use-sas-with-a-lot
> 
> To save everyone having to follow the link, the text is copied below
> 
> "SAS has some nice features, such as the SQL procedure or simple "group
> by" features. Try to compute correlations "by group" in R: say you have
> 2,000 groups, 2 variables e.g. salary and education level, and 2 million
> observations - you want to compute correlation between salary and
> education within each group.
> 
> It is not obvious, your best bet is to use some R package (see sample
> code on Analyticbridge to do it), and the solution is painful, you can
> not return both correlation and stdev "by group", as the function can
> return only one argument, not a vector. So if you want to return not
> just two, but say 100 metrics, it becomes a nightmare."
> 
> 
> 
> 
> The Numerical Algorithms Group Ltd is a company registered in England
> and Wales with company number 1249803. The registered office is:
> Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.
> 
> This e-mail has been scanned for all viruses by Star. Th...{{dropped:4}}
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@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.


  1   2   >