Re: [R] value.labels

2011-08-11 Thread David Winsemius


On Aug 11, 2011, at 10:27 AM, Uwe Ligges wrote:


On 11.08.2011 19:22, David Winsemius wrote:

Hmm, when you want to add a level without changing the class of the  
factor object, you will have to add the level at first and then  
assign the level to the elements of the object. I'd probably rebuild  
the whole thing in that case.




All I wanted to do was construct a "not done" label for the NA's in a  
factor created with cut so they would show up in tabulations. I think  
the answer to my question is to use `addNA`  and then use `levels<-`  
to change the NA level to "not done". I suppose RTFM is one way to  
answer the question and that was how I figured out what I now know.  
Looks like I can use either factor(x, exclude=NULL) or addNA(x.c)


This builds a test factor:

x<-rnorm(100)
is.na(x) <- sample(c(TRUE,FALSE), 100, c(.1,.9) , replace=TRUE)
x.c <- cut(x, seq(-3,3, by=0.5))

# I think these do the same thing:
x.cE <- factor(x, exclude=NULL)
x.cNA <- addNA(x.c)

# Relabel the NA level
levels(x.cNA) <- c(levels(x.c2)[-length(levels(x.c2))], "NotDone")

> table(x.cNA)
x.cNA
(-3,-2.5] (-2.5,-2] (-2,-1.5] (-1.5,-1] (-1,-0.5]  (-0.5,0]
(0,0.5]   (0.5,1]   (1,1.5]   (1.5,2]
0 0 3 51617 
141415 4

  (2,2.5]   (2.5,3]   NotDone
2 1 9

That seems a bit less baroque than converting to numeric , changing  
NA's to 0 and then adjusting the factor labels, although I still want  
to move the not-done level so it is first.


x.cN <- factor(x.cNA, levels=c("NotDone", c(levels(x.cNA)[- 
length(levels(x.cNA))]))

> table(x.cN)
x.cN
  NotDone (-3,-2.5] (-2.5,-2] (-2,-1.5] (-1.5,-1] (-1,-0.5]   
(-0.5,0]   (0,0.5]   (0.5,1]   (1,1.5]
9 0 0 3 516 
17141415

  (1.5,2]   (2,2.5]   (2.5,3]
4 2 1

As I understood the question, just how to rename the levels was the  
original question.


Yes, that was how I understood it as well. I was asking what I thought  
was a related question.




Uwe




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] current.panel.limits() of lattice returning NaN limits - why?

2011-08-11 Thread Fredrik Karlsson
Hi,

I need a custom axis function for a plot, but it seems
that current.panel.limits() sometimes returns NaN limits for the plot, which
it much harder to calculate anything sensible.
An illustration:

Given this axis function:


vs.axis <- function(...){
   xlim <- current.panel.limits()$xlim
   ylim <- current.panel.limits()$ylim

   # Debug code
   print(list(ylim=ylim,xlim=xlim))

   xat <- pretty(seq(xlim[1],xlim[2],100),n=5)
   yat <- pretty(seq(ylim[1],ylim[2],100),n=4)
   xlab <- sub("-","",as.character(xat))
   ylab <- sub("-","",as.character(yat))
   panel.axis(side="top",at=xat,labels=xlab)
   panel.axis(side="right",at=yat,labels=ylab)
}

and the attached data set, I get this output:

> xyplot(F1 ~F2,data=pb,axis=vs.axis)
$ylim
[1] NaN NaN

$xlim
[1]  346.5 3823.5

Error in if (del == 0 && to == 0) return(to) :
  missing value where TRUE/FALSE needed

What's wrong? Is there a more robust way of getting the x- and y- limits?

/Fredrik

-- 
"Life is like a trumpet - if you don't put anything into it, you don't get
anything out of it."
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Details of subassignment (for vectors and data frames)

2011-08-11 Thread Jeff Newmiller
My mental model is that the left hand side forms a sort of "virtual vector" 
where each element really points to an element in the vector being modified. 
Then the right hand side scalar is extended in the usual repetitious way (if 
necessary) until it is a vector just as long as the "virtual vector" on the 
left. Then the right vector is assigned to the left vector, which leaves the 
designated elements in the destination vector changed.

You could work out an equivalent for loop structure, but I think it would be 
tricky to keep the behavior for different length source and destination 
assignments straight.
---
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.

Al Roark  wrote:


Hi All: 
I'm looking to find out a bit more about how subassignment actually works and 
am hoping someone with knowledge of the details can fill me in (I've looked at 
the source code, but my knowledge of C is lacking).
In the case of vectors, my reading of ?"[" would indicate that for a vector, 
vec <- 1:25, vec[c(1,5,25)] <- c(101,102,103)is functionally the same as indx 
<- c(1,5,25) for (i in 1:length(indx)) vec[indx[i]] <- c(101,102,103)[i]
And in the case of a data frame, df <- data.frame(d1=1:10,d2=11:20,d3=21:30), 
df[c(1,5,10),c(1,3)] <- data.frame(a=101:103,b=104:106)is functionally the same 
as rowindx <- c(1,5,10) colindx <- c(1,3) for (i in 1:length(rowindx)) {  for 
(j in 1:length(colindx)) df[rowindx[i],colindx[j]] <- 
data.frame(a=101:103,b=104:106)[i,j] }Obviously I've verified 
that these examples work and I realize that my loops also contain 
subassignments; what I'm really after is to understand the mechanics of 
replacing multiple elements. Is a for-loop the proper way to understand the 
sequential nature of subassignments here (even if it is not actually 
implemented using a loop)? 
Cheers,HR
[[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] Can R handle a matrix with 8 billion entries?

2011-08-11 Thread Łukasz Ręcławowicz
W dniu 12 sierpnia 2011 05:19 u¿ytkownik Chris Howden <
ch...@trickysolutions.com.au> napisa³:

> Thanks for the suggestion, I'll look into it
>

It seems to work! :)

library(multiv)
data(iris)
iris <- as.matrix(iris[,1:4])
h <- hierclust(iris, method=2)
d<- dist(iris)
hk<-hclust(d)
>str(hk)
List of 7
$ merge : int [1:149, 1:2] -102 -8 -1 -10 -129 -11 -5 -20 -30 -58 ...
$ height : num [1:149] 0 0.1 0.1 0.1 0.1 ...
$ order : int [1:150] 108 131 103 126 130 119 106 123 118 132 ...
$ labels : NULL
$ method : chr "complete"
$ call : language hclust(d = d)
$ dist.method: chr "euclidean"
- attr(*, "class")= chr "hclust"
> str(h)
List of 3
$ merge : int [1:149, 1:2] -102 -8 -1 -10 -129 -11 -41 -5 -20 7 ...
$ height: num [1:149] 0 0.01 0.01 0.01 0.01 ...
$ order : int [1:150] 42 23 15 16 45 34 33 17 21 32 ...

test.mat<-matrix(rnorm(90523*24),,24)
out<-hierclust(test.mat, method = 1, bign = T)
> print(object.size(out),u="Mb")
1.7 Mb
> str(out)
List of 3
$ merge : int [1:90522, 1:2] -35562 -19476 -60344 -66060 -38949 -14537 -3322
-20248 -19464 -78693 ...
$ height: num [1:90522] 1.93 1.94 1.96 1.98 2 ...
$ order : int [1:90523] 24026 61915 71685 16317 85828 11577 36034 37324
65754 55381 ...
> R.version$os
[1] "mingw32"


-- 
Mi³ego dnia

[[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] Mixed Logit model mlogit error

2011-08-11 Thread FJProenza
I am new to R but I have managed to use mlogit to run multivariate logit
models successfully. My data violates the Independence of Irrelevant
Alternatives assumption and now I would like to run a mixed logit model. It
is a "wide" data set with 9 independent (individual) variables and three
choices (variable Y). The database is in a cvs file called CAU.

This is the code I have run successfully up to now. 

CAU$Y<- as.factor(CAU$Y)

mldata<-mlogit.data(CAU, varying=NULL, choice="Y", shape="wide")

mlogit.model<-mlogit(Y~1|Gender+Age+Net+CompT+Hrs+Motivado+Visits+StudyT+HrsVis,data=mldata,reflevel="1")

I am having problems running the mixed logit model. I have changed (only)
the mlogit command, as follows  

mlogit.model<-mlogit(Y~1|Gender+Age+Net+CompT+Hrs+Motivado+Visits+StudyT+HrsVis,
data=mldata,reflevel="1",rpar=c(Gender="u",Age="u",Lower="u",Mid="u",Net="u",CompT="u",Hrs="u",StudyT="u",HrsVis="u"),
correlation=TRUE, drop.index=FALSE, R=500, halton = NA)

When I try to run this command, I get the following error messages:

Error: object of type 'symbol' is not subsettable
In addition: Warning messages:
1: In if (shape == "long") { :
  the condition has length > 1 and only the first element will be used
2: In if (shape == "wide") { :
  the condition has length > 1 and only the first element will be used

Any help you can give me will be much appreciated.


--
View this message in context: 
http://r.789695.n4.nabble.com/Mixed-Logit-model-mlogit-error-tp3737893p3737893.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] Details of subassignment (for vectors and data frames)

2011-08-11 Thread Al Roark

Hi All: 
I'm looking to find out a bit more about how subassignment actually works and 
am hoping someone with knowledge of the details can fill me in (I've looked at 
the source code, but my knowledge of C is lacking).
In the case of vectors, my reading of ?"[" would indicate that for a vector, 
vec <- 1:25,vec[c(1,5,25)] <- c(101,102,103)is functionally the same as
indx <- c(1,5,25)for (i in 1:length(indx)) vec[indx[i]] <- c(101,102,103)[i]
And in the case of a data frame, df <- data.frame(d1=1:10,d2=11:20,d3=21:30),   
 df[c(1,5,10),c(1,3)] <- data.frame(a=101:103,b=104:106)is functionally the 
same asrowindx <- c(1,5,10)colindx <- c(1,3)for (i in 
1:length(rowindx)) {  for (j in 1:length(colindx)) 
df[rowindx[i],colindx[j]] <- data.frame(a=101:103,b=104:106)[i,j]}  
   Obviously I've verified that these examples work and I realize that my loops 
also contain subassignments; what I'm really after is to understand the 
mechanics of replacing multiple elements.  Is a for-loop the proper way to 
understand the sequential nature of subassignments here (even if it is not 
actually implemented using a loop)? 
Cheers,HR 
[[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] sapply( ) a loop function

2011-08-11 Thread R. Michael Weylandt
The previous two posters basically covered everything, but since I'm on the
train with not too much to do, here's a more detailed response building on
what they said. The following code is "shovel-ready" and can be pasted
directly to your command line if you have your main data frame called "d"
available.

- BEGIN R CODE -

# This will install the (awesome) plyr package if you don't already have it
on your machine
# Feel free to comment it out if you know you have plyr already.
#install.packages("plyr")

require(plyr)
# This loads the plyr package which adds a bunch of variants on the "apply"
family
# We will use a variant below that's more appropriate for what you are
trying to do
# sapply() wouldn't be a problem, but this lets us have that little bit
extra control
# over the call that makes R great

# Create some sample data
# fish = rep(1:3,241*3)
# d2p = seq((50/241),50,(50/241))
# d2p = c(d2p,d2p,d2p)
# d = data.frame(fish,d2p)

# This creates a list of data frames, as you rightly identified.
split.df <- split(d,d$fish)

# Set up the function -- I gave it a whimsical name because I have no idea
what this
# is intended to do or why you want to do it. Of course, you should feel
free to adapt it to
# something more "professional". I don't know if you've seen the general
function syntax before,
# but this sets up a function with optional additional inputs; defaults are
set in the
# top of the function definition. They match the parameters of your problem,
so you
# won't need to change them later.

FunFishFunction <- function(fish, n = 241, n2 = 40, chemLevel = 5, chemName
= "d2p") {
test <- 0; iters = 0
while(test < chemLevel){
i <- sample(1:(n-n2),1)
test = sum(fish[i:(i+n2), chemName], na.rm=T)

# Some catch code to make sure you don't wind up in an infinite loop
# If you get to a large number of iterations, this will check to
make sure
# it is possible to find the desired place and return it if
possible; marks both of these escape cases
# so they can be identified if desired later.
if (iters > 50) {
s = cumsum(na.omit(fish[,chemName]))
s = diff(s, lag = n2)
if (max(s) < chemLevel) {
return(c(Inf,max(s))) # Return an Infinity to indicate it
can't be done.
} else {return(c(which.max(s>chemLevel), chemLevel))}
# Return the first passing spot and the critical value
}
iters = iters + 1
}
return(c(i,test))
# As noted, it's good form to explicitly return any results in a
user-defined function
# By doing so here, we could halt function execution as noted in our
escape code above
# We simply bind them together with c() here so both can be directly
returned
}

# This is where the plyr package comes in. It takes in a "l" -- list, "ply"s
it and returns
# a "d" -- data frame. The general plyr package has variants like llply or
aaply or
# daply or whatever you may need.  (a = array)
# It also provides a nifty progress bar for longer calculations so you don't
drive yourself crazy waiting :-)
# If you want to override the defaults we set above, simply put "n = 250" or
whatever between the
# function name and the call to the progress bar.

# The general syntax is tTply(IN,FUNC,FUNC_OPTIONS,PLY_OPTIONS)
# t is a code indicating the type of thing going in
# T indicates the type of thing coming out
# IN is the thing going in
# FUNC is the function to be "ply"d
# FUNC_OPTIONS are additional things to be passed to FUNC. There are none
here
# PLY_OPTIONS are additional options for the **ply function -- here we
invoke a progress bar.

FishConclusions = ldply(split.df,FunFishFunction, .progress = 'text')

colnames(FishConclusions) <- c("Fish Number", "i","test")
# Add informative column names to our data frame

print(FishConclusions)

 END R CODE --

Hopefully this helps!
Good luck and feel free to get in touch if I can clarify any of this or be
of further help.

Michael Weylandt

On Thu, Aug 11, 2011 at 8:02 PM, Dennis Murphy  wrote:

> Hi:
>
> samp_func() doesn't return anything. Either (1) type test as the last
> line of the function body or (2) don't assign the last sum to an
> object.
>
> HTH,
> Dennis
>
> On Thu, Aug 11, 2011 at 1:59 PM, Sean Bignami  wrote:
> > Hello R-universe...
> >
> > I am having trouble writing a function which contains a loop so I can
> sapply() it to a list of data frames
> >
> > Each data frame has 241 observations of 15 variables. My loop takes a
> random sample of one row until the 40 consecutive rows after the sample have
> a d2p(variable) sum greater than 5.
> >
> > here is my loop code (it works fine when applied to a 241 observation
> data frame):
> >
> >n<-241
> >test<-0
> >while(test<5){
> >i<-sample(1:n-40,1)
> >x<-my.data.frame[seq(from=i, to=i+40),]
> >test<-sumx[,"d2p"],na.rm=TRUE)
> >

Re: [R] value.labels

2011-08-11 Thread Daniel Nordlund

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of Rolf Turner
> Sent: Thursday, August 11, 2011 5:24 PM
> To: Heinz Tuechler
> Cc: Zeki Çatav; r-help@r-project.org; Uwe Ligges
> Subject: Re: [R] value.labels
> 
> On 12/08/11 12:53, Heinz Tuechler wrote:
> > At 12.08.2011 11:05 +1200, Rolf Turner wrote:
> >> On 12/08/11 11:34, Heinz Tuechler wrote:
> >>> At 12.08.2011 09:11 +1200, Rolf Turner wrote:
>  On 12/08/11 09:59, Heinz Tuechler wrote:
> > At 11.08.2011 21:50 +0300, Zeki Çatav wrote:
> >> Prş, 2011-08-11 tarihinde 19:27 +0200 saatinde, Uwe Ligges yazdı:
> >> >
> >> > On 11.08.2011 19:22, David Winsemius wrote:
> >> > >
> >> > > On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:
> >> > >
> >> > >>
> >> > >>
> >> > >> On 11.08.2011 16:10, zcatav wrote:
> >> > >>> Hello R people,
> >> > >>>
> >> > >>> I have a "data.frame". Status variable has 3 values. 0-
> >alive,
> >> > >>> 1->dead and
> >> > >>> 2->missed..
> >> > .
> >> > As I understood the question, just how to rename the levels was
> >> the
> >> > original question.
> >> >
> >> > Uwe
> >>
> >> I don't want to rename levels or converting from numeric to
> >> string. I
> >> want to add each corresponding levels value, a label, as in SPSS.
> >> Level 0 labeled with alive,
> >> level 1 labeled with dead and
> >> level 2 labeled with missed.
> >
> > This is not possible with a factor, because factor levels can only
> > be positive integers.
> 
>  That is just plain (ridiculously) wrong. RTFM.
> 
>  cheers,
> 
>  Rolf Turner
> >>>
> >>> So, how would you construct a factor with levels 0, 1, 2 and labels
> >>> alive, dead, and missed, as the original post asked for?
> >>>
> >>> Heinz
> >>
> >> As I said, RTFM. But for completeness:
> >>
> >> x <- sample(0:2,100,TRUE)
> >> y <- factor(x,labels=c("alive","dead","missed"))
> >>
> >> Duhhh.
> >>
> >> cheers,
> >>
> >> Rolf Turner
> >
> > Maybe you would like to look at the structure.
> >
> > str(y)
> > Factor w/ 3 levels "alive","dead",..: 3 1 2 2 3 3 2 1 1 1 ...
> >
> > or
> >
> > dput(y)
> > structure(c(3L, 1L, 2L, 2L, 3L, 3L, 2L, 1L, 1L, 1L, 2L, 1L, 3L,
> > 1L, 2L, 3L, 2L, 2L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 2L, 1L, 2L, 1L,
> > 1L, 3L, 1L, 2L, 3L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 3L,
> > 2L, 1L, 2L, 3L, 3L, 2L, 1L, 1L, 2L, 3L, 3L, 2L, 1L, 3L, 1L, 1L,
> > 2L, 2L, 1L, 2L, 1L, 2L, 3L, 3L, 3L, 2L, 3L, 3L, 1L, 2L, 3L, 2L,
> > 3L, 1L, 3L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 3L, 2L, 2L, 1L, 1L, 1L,
> > 2L, 3L, 3L, 2L, 1L, 2L, 3L), .Label = c("alive", "dead", "missed"
> > ), class = "factor")
> > >
> >
> > Anything else but positive integers?
> >
> 
> You clearly do not understand factors. RTFM.
> 
> cheers,
> 
> Rolf Turner
> 

Rolf,

Clearly, someone doesn't understand something, and it may be me.  I understood 
the OP to be asking if there was a way of adding labels to specific variable 
values without changing the underlying values (like a format in SAS or 
apparently "value labels" in SPSS).  To use your example

x <- sample(0:2,100,TRUE)

The OP wanted to "associate" the label "alive" with the value 0, but didn't 
want the underlying value in x to change.  The construction 

y <- factor(x,labels=c("alive","dead","missed"))

creates a factor, y, where the underlying factor value is 1 and the label is 
"alive" where x had the value of 0.  Without retaining the vector x, or knowing 
how y was created, one can't get back to the original value of 0.  I am 
agnostic about whether that is good or bad, but it seems that your approach 
does not meet the OP's original request.  Am I missing someting?

Dan

Daniel Nordlund
Bothell, WA USA

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


Re: [R] value.labels

2011-08-11 Thread Rolf Turner

On 12/08/11 12:53, Heinz Tuechler wrote:

At 12.08.2011 11:05 +1200, Rolf Turner wrote:

On 12/08/11 11:34, Heinz Tuechler wrote:

At 12.08.2011 09:11 +1200, Rolf Turner wrote:

On 12/08/11 09:59, Heinz Tuechler wrote:

At 11.08.2011 21:50 +0300, Zeki Çatav wrote:

Prş, 2011-08-11 tarihinde 19:27 +0200 saatinde, Uwe Ligges yazdı:
>
> On 11.08.2011 19:22, David Winsemius wrote:
> >
> > On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:
> >
> >>
> >>
> >> On 11.08.2011 16:10, zcatav wrote:
> >>> Hello R people,
> >>>
> >>> I have a "data.frame". Status variable has 3 values. 0->alive,
> >>> 1->dead and
> >>> 2->missed..
> .
> As I understood the question, just how to rename the levels was 
the

> original question.
>
> Uwe

I don't want to rename levels or converting from numeric to 
string. I

want to add each corresponding levels value, a label, as in SPSS.
Level 0 labeled with alive,
level 1 labeled with dead and
level 2 labeled with missed.


This is not possible with a factor, because factor levels can only 
be positive integers.


That is just plain (ridiculously) wrong. RTFM.

cheers,

Rolf Turner


So, how would you construct a factor with levels 0, 1, 2 and labels 
alive, dead, and missed, as the original post asked for?


Heinz


As I said, RTFM. But for completeness:

x <- sample(0:2,100,TRUE)
y <- factor(x,labels=c("alive","dead","missed"))

Duhhh.

cheers,

Rolf Turner


Maybe you would like to look at the structure.

str(y)
Factor w/ 3 levels "alive","dead",..: 3 1 2 2 3 3 2 1 1 1 ...

or

dput(y)
structure(c(3L, 1L, 2L, 2L, 3L, 3L, 2L, 1L, 1L, 1L, 2L, 1L, 3L,
1L, 2L, 3L, 2L, 2L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 2L, 1L, 2L, 1L,
1L, 3L, 1L, 2L, 3L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 3L,
2L, 1L, 2L, 3L, 3L, 2L, 1L, 1L, 2L, 3L, 3L, 2L, 1L, 3L, 1L, 1L,
2L, 2L, 1L, 2L, 1L, 2L, 3L, 3L, 3L, 2L, 3L, 3L, 1L, 2L, 3L, 2L,
3L, 1L, 3L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 3L, 2L, 2L, 1L, 1L, 1L,
2L, 3L, 3L, 2L, 1L, 2L, 3L), .Label = c("alive", "dead", "missed"
), class = "factor")
>

Anything else but positive integers?



You clearly do not understand factors. RTFM.

cheers,

Rolf Turner

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


Re: [R] value.labels

2011-08-11 Thread Heinz Tuechler

At 12.08.2011 01:53 +0100, Heinz Tuechler wrote:

At 12.08.2011 11:05 +1200, Rolf Turner wrote:

On 12/08/11 11:34, Heinz Tuechler wrote:

At 12.08.2011 09:11 +1200, Rolf Turner wrote:

On 12/08/11 09:59, Heinz Tuechler wrote:

At 11.08.2011 21:50 +0300, Zeki Çatav wrote:

Prş, 2011-08-11 tarihinde 19:27 +0200 saatinde, Uwe Ligges yazdı:
>
> On 11.08.2011 19:22, David Winsemius wrote:
> >
> > On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:
> >
> >>
> >>
> >> On 11.08.2011 16:10, zcatav wrote:
> >>> Hello R people,
> >>>
> >>> I have a "data.frame". Status variable has 3 values. 0->alive,
> >>> 1->dead and
> >>> 2->missed..
> .
> As I understood the question, just how to rename the levels was the
> original question.
>
> Uwe

I don't want to rename levels or converting from numeric to string. I
want to add each corresponding levels value, a label, as in SPSS.
Level 0 labeled with alive,
level 1 labeled with dead and
level 2 labeled with missed.


This is not possible with a factor, because 
factor levels can only be positive integers.


That is just plain (ridiculously) wrong. RTFM.

cheers,

Rolf Turner


So, how would you construct a factor with 
levels 0, 1, 2 and labels alive, dead, and 
missed, as the original post asked for?


Heinz


As I said, RTFM. But for completeness:

x <- sample(0:2,100,TRUE)
y <- factor(x,labels=c("alive","dead","missed"))

Duhhh.

cheers,

Rolf Turner


Maybe you would like to look at the structure.

str(y)
Factor w/ 3 levels "alive","dead",..: 3 1 2 2 3 3 2 1 1 1 ...

or

dput(y)
structure(c(3L, 1L, 2L, 2L, 3L, 3L, 2L, 1L, 1L, 1L, 2L, 1L, 3L,
1L, 2L, 3L, 2L, 2L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 2L, 1L, 2L, 1L,
1L, 3L, 1L, 2L, 3L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 3L,
2L, 1L, 2L, 3L, 3L, 2L, 1L, 1L, 2L, 3L, 3L, 2L, 1L, 3L, 1L, 1L,
2L, 2L, 1L, 2L, 1L, 2L, 3L, 3L, 3L, 2L, 3L, 3L, 1L, 2L, 3L, 2L,
3L, 1L, 3L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 3L, 2L, 2L, 1L, 1L, 1L,
2L, 3L, 3L, 2L, 1L, 2L, 3L), .Label = c("alive", "dead", "missed"
), class = "factor")
>

Anything else but positive integers?

Heinz


To be fair, you can construct a factor containing zeros.

b <- c(0L,0L,1L,1L,1L,2L,2L,2L,2L)
> b
[1] 0 0 1 1 1 2 2 2 2
> str(b)
 int [1:9] 0 0 1 1 1 2 2 2 2
> table(b)
b
0 1 2
2 3 4
> levels(b) <- letters[1:3]
> str(b)
 atomic [1:9] 0 0 1 1 1 2 2 2 2
 - attr(*, "levels")= chr [1:3] "a" "b" "c"
> class(b) <- 'factor'
> str(b)
 Factor w/ 3 levels "a","b","c": 0 0 1 1 1 2 2 2 2

But, if you print it, you get a warning.

> b
[1] a a a b b b b a a
Levels: a b c
Warning message:
In xx[] <- as.character(x) :
  number of items to replace is not a multiple of replacement length

And table() gives a wrong result.
> table(b)
b
a b c
3 4 0
>

If you take a numeric, not explicitly integer vector, you are less lucky.

c <- c(0,0,1,1,1,2,2,2,2)
> str(c)
 num [1:9] 0 0 1 1 1 2 2 2 2
> levels(c) <- letters[1:3]
> str(c)
 atomic [1:9] 0 0 1 1 1 2 2 2 2
 - attr(*, "levels")= chr [1:3] "a" "b" "c"

Assigning class "factor" is rejected with an error.
> class(c) <- 'factor'
Error in class(c) <- "factor" :
  adding class "factor" to an invalid object
>

Heinz


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

2011-08-11 Thread Dennis Murphy
Hi:

samp_func() doesn't return anything. Either (1) type test as the last
line of the function body or (2) don't assign the last sum to an
object.

HTH,
Dennis

On Thu, Aug 11, 2011 at 1:59 PM, Sean Bignami  wrote:
> Hello R-universe...
>
> I am having trouble writing a function which contains a loop so I can 
> sapply() it to a list of data frames
>
> Each data frame has 241 observations of 15 variables. My loop takes a random 
> sample of one row until the 40 consecutive rows after the sample have a 
> d2p(variable) sum greater than 5.
>
> here is my loop code (it works fine when applied to a 241 observation data 
> frame):
>
>        n<-241
>        test<-0
>        while(test<5){
>                i<-sample(1:n-40,1)
>                x<-my.data.frame[seq(from=i, to=i+40),]
>                test<-sumx[,"d2p"],na.rm=TRUE)
>                }; i ; test
>
> I need this loop to be applied to EACH DATA FRAME in a list of 360 data 
> frames created by splitting my master data frame, d, by each fish number. 
> (contains observations for 360 fish, each with 241 observations of 15 
> variables).
>
>        split.df<-split(d,d$fish)
>
> I'm kind of new at writing functions, so I'm sure this probably doesn't make 
> much sense, but here is what I tried for the function:
>
>        samp.func<-function(f) {
>        n<-241
>        test<-0
>        while(test<5){
>                i<-sample(1:n-40,1)
>                x<-f[seq(from=i, to=i+40),]
>                test<-sum(x[,"d2p"],na.rm=TRUE)
>                }}
>
> and then tried to apply it to my list of data frames (NOT WORKING):
>
>        sapply(split.df,samp.func)
>
> I'm pretty sure I'm missing some way to instruct that I want the loop to 
> cycle through for each item (data frame) in my split.df list. I've tried to 
> play around with including "for" loops with no avail...
>
> any ideas?
>
>
>
> here is code for a simplified mock single-fish data frame (i.e. one item in 
> my split.df list) to plug into the loop if you want to try it.
>
> fish<-rep(1,241)
> d2p<-seq((50/241),50,(50/241))
> my.data.frame<-data.frame(fish,d2p)
>
> thanks!!
> Sean
>
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] value.labels

2011-08-11 Thread Heinz Tuechler

At 12.08.2011 11:05 +1200, Rolf Turner wrote:

On 12/08/11 11:34, Heinz Tuechler wrote:

At 12.08.2011 09:11 +1200, Rolf Turner wrote:

On 12/08/11 09:59, Heinz Tuechler wrote:

At 11.08.2011 21:50 +0300, Zeki Çatav wrote:

Prş, 2011-08-11 tarihinde 19:27 +0200 saatinde, Uwe Ligges yazdı:
>
> On 11.08.2011 19:22, David Winsemius wrote:
> >
> > On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:
> >
> >>
> >>
> >> On 11.08.2011 16:10, zcatav wrote:
> >>> Hello R people,
> >>>
> >>> I have a "data.frame". Status variable has 3 values. 0->alive,
> >>> 1->dead and
> >>> 2->missed..
> .
> As I understood the question, just how to rename the levels was the
> original question.
>
> Uwe

I don't want to rename levels or converting from numeric to string. I
want to add each corresponding levels value, a label, as in SPSS.
Level 0 labeled with alive,
level 1 labeled with dead and
level 2 labeled with missed.


This is not possible with a factor, because 
factor levels can only be positive integers.


That is just plain (ridiculously) wrong. RTFM.

cheers,

Rolf Turner


So, how would you construct a factor with 
levels 0, 1, 2 and labels alive, dead, and 
missed, as the original post asked for?


Heinz


As I said, RTFM. But for completeness:

x <- sample(0:2,100,TRUE)
y <- factor(x,labels=c("alive","dead","missed"))

Duhhh.

cheers,

Rolf Turner


Maybe you would like to look at the structure.

str(y)
Factor w/ 3 levels "alive","dead",..: 3 1 2 2 3 3 2 1 1 1 ...

or

dput(y)
structure(c(3L, 1L, 2L, 2L, 3L, 3L, 2L, 1L, 1L, 1L, 2L, 1L, 3L,
1L, 2L, 3L, 2L, 2L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 2L, 1L, 2L, 1L,
1L, 3L, 1L, 2L, 3L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 3L,
2L, 1L, 2L, 3L, 3L, 2L, 1L, 1L, 2L, 3L, 3L, 2L, 1L, 3L, 1L, 1L,
2L, 2L, 1L, 2L, 1L, 2L, 3L, 3L, 3L, 2L, 3L, 3L, 1L, 2L, 3L, 2L,
3L, 1L, 3L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 3L, 2L, 2L, 1L, 1L, 1L,
2L, 3L, 3L, 2L, 1L, 2L, 3L), .Label = c("alive", "dead", "missed"
), class = "factor")
>

Anything else but positive integers?

Heinz

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Reduce the space under legend title

2011-08-11 Thread Amelia McNamara
I would like to know if there is a way to reduce the space between the
legend title and the first line of the legend, without reducing all
the vertical space using y.intersp. Because of lack of space, I would
like to differentiate my title by bolding it, and reduce the vertical
space under the title to the space typically used between categories
in a legend.

plot(c(1.1, 2.3, 4.6), c(2.0, 1.6, 3.2), pch=c(1,2,3))
legend(x="bottomright", legend=c("Category 1", "Category 2", "Category
3"), title=expression(bold("Fairly long title")), pch=c(1,2,3),
bty="o")

~Amelia McNamara
Statistics PhD student, UCLA

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


Re: [R] Sample size AUC for ROC curves

2011-08-11 Thread Karl Knoblick
Thanks. Actually I thought of something like 
Hanley JA, McNeil BJ. A method of comparing the areas under receiver operating 
characteristic curves derived from the same cases. Radiology. 1983; 148: 
839–843.
http://radiology.rsna.org/content/148/3/839.full.pdf+html
 
Has anybody R-code for this or something similar but newer?
 
The question is just easy - How many subjects do I need if I want to show that 
my diagnostic test is not only a game of dice. Data for input are the epected 
AUC, alpha and beta,
 
Would be great if somebody has a solution!
 
Karl



- Ursprüngliche Mail 
Von: Greg Snow 
An: Karl Knoblick ; "r-h...@stat.math.ethz.ch" 

Gesendet: Dienstag, den 9. August 2011, 19:45:12 Uhr
Betreff: RE: [R] Sample size AUC for ROC curves

If you know how to generate random data that represents your null hypothesis 
(chance, auc=0.5) and how to do your analysis, then you can do this by 
simulation, simulate a dataset at a given sample size, analyze it, repeat a 
bunch of times and see if that sample size is about the right size.  If not, do 
it again with a different sample size until you find one that works for you.

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


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Karl Knoblick
> Sent: Monday, August 08, 2011 3:29 PM
> To: r-h...@stat.math.ethz.ch
> Subject: [R] Sample size AUC for ROC curves
> 
> Hallo!
> 
> Does anybody know a way to calculate the sample size for comparing AUC
> of ROC
> curves against 'by chance' with AUC=0.5 (and/or against anothe AUC)?
> 
> Thanks!
> Karl
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] value.labels

2011-08-11 Thread Rolf Turner

On 12/08/11 11:34, Heinz Tuechler wrote:

At 12.08.2011 09:11 +1200, Rolf Turner wrote:

On 12/08/11 09:59, Heinz Tuechler wrote:

At 11.08.2011 21:50 +0300, Zeki Çatav wrote:

Prş, 2011-08-11 tarihinde 19:27 +0200 saatinde, Uwe Ligges yazdı:
>
> On 11.08.2011 19:22, David Winsemius wrote:
> >
> > On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:
> >
> >>
> >>
> >> On 11.08.2011 16:10, zcatav wrote:
> >>> Hello R people,
> >>>
> >>> I have a "data.frame". Status variable has 3 values. 0->alive,
> >>> 1->dead and
> >>> 2->missed..
> .
> As I understood the question, just how to rename the levels was the
> original question.
>
> Uwe

I don't want to rename levels or converting from numeric to string. I
want to add each corresponding levels value, a label, as in SPSS.
Level 0 labeled with alive,
level 1 labeled with dead and
level 2 labeled with missed.


This is not possible with a factor, because factor levels can only 
be positive integers.


That is just plain (ridiculously) wrong. RTFM.

cheers,

Rolf Turner


So, how would you construct a factor with levels 0, 1, 2 and labels 
alive, dead, and missed, as the original post asked for?


Heinz


As I said, RTFM. But for completeness:

x <- sample(0:2,100,TRUE)
y <- factor(x,labels=c("alive","dead","missed"))

Duhhh.

cheers,

Rolf Turner

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


Re: [R] Mixed effect models

2011-08-11 Thread Daniel Malter
I am afraid this is one of these posts where I have to quote David Winsemius:
"The advancement of science would be safer if you knew what you were doing."
Moreover, these are questions best addressed to your local statistician
rather than the R-help list. With exceptions, the R-help list helps to solve
questions about/problems with R, but not about your empirical modeling
strategy per se. The reason for this is sound: we do not know what you are
doing.

As for your first question: I do not see, why you would want to compute a
p-value by hand, because the output provides a p-value for the fixed
effects.

Also, green roof does not have a negative "trend" with Totalabundance. Your
Habitat variable is a categorical variable and thus compares Totalabundance
between the (obviously three) categories of Habitat. Therefore, there is not
trend but only categorical distinctions here.  The intercept tells you the
average value of Totalabundance for the first category of Habitat. The
HabitatGreen roof coefficient tells you whether Totalabundance is
significantly different for the first and second category of Habitat. The
coefficient of HabitatGreen space tells you whether the first and third
category are significantly different in Totalabundance.

Your results (if modeled properly) would indicate that there is no
significant difference between the first  (the omitted baseline absorbed by
the intercept) and the third (HabitatGreen space) category. There may be a
significant difference in Totalabundance between the first and the second
(HabitatGreen roof) category, but the evidence is statistically weak (only
marginally significant at the 10 percent level).

The step of getting into more complex analyses (pertaining to your question
about interaction terms, etc.), should only follow a thorough study of the
basics of ANOVA/regression analysis.

HTH,
Daniel





Eleanor Spratt wrote:
> 
> I am using two mixed effect models. Firstly, what I am trying to do is to
> compare green roofs abundance with brownfield, green roof with green space
> abundance, and finally green
> space with brownfield abundance. I am unsure if I have done the
> correct model. I have to use a mixed effect model because my data is
> nested.
> 
> This is the code and output
> 
>> model1<-lmer(Total.abundance~Habitat+(1|Site)+(1|Week),REML=FALSE,family=poisson)
>> summary(model1)
> 
> Generalized linear mixed model fit by the Laplace approximation
> Formula: Total.abundance ~ Habitat + (1 | Site) + (1 | Week)
>  AIC  BIC logLik deviance
>  1780 1795 -884.9 1770
> Random effects:
>  Groups NameVariance Std.Dev.
>  Site   (Intercept) 0.62318  0.78941
>  Week   (Intercept) 0.13883  0.37260
> Number of obs: 150, groups: Site, 15; Week, 10
> 
> Fixed effects:
>   Estimate Std. Error z value Pr(>|z|)
> (Intercept)  2.8116 0.3740   7.517 5.59e-14 ***
> HabitatGreen roof   -0.8676 0.5040  -1.721   0.0852 .
> HabitatGreen space   0.2008 0.5021   0.400   0.6892
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> 
> Correlation of Fixed Effects:
>(Intr) HbttGr
> HabittGrnrf -0.668
> HabttGrnspc -0.671  0.498
> 
> From this I understand that green roof has a negative trend with
> brownfield, and green space has no significance with brownfield. But
> what about green roof and green space Is there a way of
> interpreting this information from the above data. Is it like ANOVA
> where you have to manually calculate the p value. Or do I have to
> simplify this model by reducing my Habitat factors levels (e.g.
> combining green space and brownfield together).
> 
> My second mixed effect model is seeing if environmental factors influence
> the mixed effect model, but I want to use interactions. When I plot this I
> get an error message.
> 
>> model1<-lmer(Total.abundance~(area+Hemeroby+Age+isolation+Height+Bare.ground+Grass+Non.grass)^2+(1|Site)+(1|Week),REML=FALSE,family=poisson)
> 
> Error: inner loop 1; cannot correct step size
> In addition: Warning message:
> step size truncated due to divergence 
> 
> Thus I tried it without interactions- 
>> model1<-lmer(Total.abundance~area+Hemeroby+Age+isolation+Height+Bare.ground+Grass+Non.grass+(1|Site)+(1|Week),REML=FALSE,family=poisson)
> 
> but with a couple of simplifications of the model the intercept was not
> significant, so I dont' know what to do.
> 
> Kind Regards
> 
> Ellie
> 

--
View this message in context: 
http://r.789695.n4.nabble.com/Mixed-effect-models-tp3737266p3737514.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] Removing all duplicate row except by one

2011-08-11 Thread Rolf Turner

On 12/08/11 07:37, m.marcinmichal wrote:

Hi,
It's my problem, supppose that we have a data.frame:

t
   a b c
1 1 1 1
2 0 1 1
3 1 1 1
4 0 0 0
5 1 0 1
6 0 1 0
7 1 1 1
8 0 1 0

I need extract duplicat row i.e i nedd frame like this

   a b c
3 1 1 1
8 0 1 0

I try use subset(t, duplicated(t)) and t[duplicated(t), ] but this command
return

   a b c
3 1 1 1
7 1 1 1
8 0 1 0


unique(t[duplicated(t),])

BTW "t" is not a good name for an object since it is the name of a
base function in R (the transpose function).

cheers,

Rolf Turner

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


Re: [R] value.labels

2011-08-11 Thread Heinz Tuechler

At 12.08.2011 09:11 +1200, Rolf Turner wrote:

On 12/08/11 09:59, Heinz Tuechler wrote:

At 11.08.2011 21:50 +0300, Zeki Çatav wrote:

Prş, 2011-08-11 tarihinde 19:27 +0200 saatinde, Uwe Ligges yazdı:
>
> On 11.08.2011 19:22, David Winsemius wrote:
> >
> > On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:
> >
> >>
> >>
> >> On 11.08.2011 16:10, zcatav wrote:
> >>> Hello R people,
> >>>
> >>> I have a "data.frame". Status variable has 3 values. 0->alive,
> >>> 1->dead and
> >>> 2->missed..
> .
> As I understood the question, just how to rename the levels was the
> original question.
>
> Uwe

I don't want to rename levels or converting from numeric to string. I
want to add each corresponding levels value, a label, as in SPSS.
Level 0 labeled with alive,
level 1 labeled with dead and
level 2 labeled with missed.


This is not possible with a factor, because 
factor levels can only be positive integers.


That is just plain (ridiculously) wrong. RTFM.

cheers,

Rolf Turner


So, how would you construct a factor with levels 
0, 1, 2 and labels alive, dead, and missed, as the original post asked for?


Heinz

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

2011-08-11 Thread Wensui Liu
it is in the consumer risk modeling team in Cincinnati ohio.

pls send resume to wensui@53.com if interested.

thx

[[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] attribute name argument for getAttrib()

2011-08-11 Thread Wei Hao
Hi all:

Having browsed Rinternals.h, it's a little unclear to me how to get 
attributes that aren't in the "Symbol Table Shortcuts" section of that 
file. In particular, I would like to extract the attribute 
"scaled:center" from a SEXP.

Thanks


[[alternative HTML version deleted]]

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


Re: [R] sapply( ) a loop function

2011-08-11 Thread Daniel Malter
I am not sure what purpose the while loop has. However, the main problem
seems to be that you need to put:

i<-sample(1:(n-40),1) #This sample from 1 to n-40

rather than 

i<-sample(1:n-40,1) #this samples one 1:n and then subtracts 40

Otherwise, you may get negative index values

Best,
Daniel



bignami83 wrote:
> 
> Hello R-universe...
> 
> I am having trouble writing a function which contains a loop so I can
> sapply() it to a list of data frames
> 
> Each data frame has 241 observations of 15 variables. My loop takes a
> random sample of one row until the 40 consecutive rows after the sample
> have a d2p(variable) sum greater than 5.
> 
> here is my loop code (it works fine when applied to a 241 observation data
> frame):
> 
>   n<-241
>   test<-0
>   while(test<5){
>   i<-sample(1:n-40,1)
>   x<-my.data.frame[seq(from=i, to=i+40),]
>   test<-sumx[,"d2p"],na.rm=TRUE)
>   }; i ; test
> 
> I need this loop to be applied to EACH DATA FRAME in a list of 360 data
> frames created by splitting my master data frame, d, by each fish number.
> (contains observations for 360 fish, each with 241 observations of 15
> variables).
> 
>   split.df<-split(d,d$fish)
> 
> I'm kind of new at writing functions, so I'm sure this probably doesn't
> make much sense, but here is what I tried for the function:
> 
>   samp.func<-function(f) {
>   n<-241
>   test<-0
>   while(test<5){
>   i<-sample(1:n-40,1)
>   x<-f[seq(from=i, to=i+40),]
>   test<-sum(x[,"d2p"],na.rm=TRUE)
>   }}
> 
> and then tried to apply it to my list of data frames (NOT WORKING):
> 
>   sapply(split.df,samp.func)
> 
> I'm pretty sure I'm missing some way to instruct that I want the loop to
> cycle through for each item (data frame) in my split.df list. I've tried
> to play around with including "for" loops with no avail...
> 
> any ideas?
> 
> 
> 
> here is code for a simplified mock single-fish data frame (i.e. one item
> in my split.df list) to plug into the loop if you want to try it. 
> 
> fish<-rep(1,241)
> d2p<-seq((50/241),50,(50/241))
> my.data.frame<-data.frame(fish,d2p)
> 
> thanks!!
> Sean
> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

--
View this message in context: 
http://r.789695.n4.nabble.com/sapply-a-loop-function-tp3737261p3737481.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] Removing all duplicate row except by one

2011-08-11 Thread Justin
m.marcinmichal  gmail.com> writes:

> 
> Hi,
> It's my problem, supppose that we have a data.frame:
> 
-snip-

You should avoid using t as a variable name since its an important
R function!


> I need extract duplicat row i.e i nedd frame like this
> 
>   a b c
> 3 1 1 1
> 8 0 1 0
> 

not sure if this will get you there but if you data is 
in a variable named dat... 


> unique(dat[duplicated(dat),])
  a b c
3 1 1 1
8 0 1 0


> I try use subset(t, duplicated(t)) and t[duplicated(t), ] but this command
> return
> 
>   a b c
> 3 1 1 1
> 7 1 1 1
> 8 0 1 0
> 
> Best
> 
> Marcin M.
> 
> --
> View this message in context:
http://r.789695.n4.nabble.com/Removing-all-duplicate-row-except-by-one-tp3736949p3736949.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] Cv.glment question -- why giving me an error

2011-08-11 Thread Patrick Breheny

On 08/11/2011 01:01 PM, Andra Isan wrote:

Hi All,
I am trying to run cv.glmnet(x,y,family="multinomial", nfolds =4) and I only 
have 8 observations and the number of features I have is 1000, so my x matrix is 8 by 
1000 and when I run the following, I get this error, I am not sure what is causing this 
problem.
Error in predmat[which, , seq(nlami)] = preds :   number of items to replace is 
not a multiple of replacement length
Can it be because the number of observations is small?
Thanks a lot,Andra
[[alternative HTML version deleted]]



1) My guess is that you do not have an observation in each class in each 
fold.  It would be rather difficult to estimate the probability of 
belonging to a class without any data.


2) Do you really hope to obtain a meaningful fit for a multinomial model 
with only 8 observations?  How many classes do you have?


--
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] value.labels

2011-08-11 Thread Rolf Turner

On 12/08/11 09:59, Heinz Tuechler wrote:

At 11.08.2011 21:50 +0300, Zeki Çatav wrote:

Prş, 2011-08-11 tarihinde 19:27 +0200 saatinde, Uwe Ligges yazdı:
>
> On 11.08.2011 19:22, David Winsemius wrote:
> >
> > On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:
> >
> >>
> >>
> >> On 11.08.2011 16:10, zcatav wrote:
> >>> Hello R people,
> >>>
> >>> I have a "data.frame". Status variable has 3 values. 0->alive,
> >>> 1->dead and
> >>> 2->missed..
> .
> As I understood the question, just how to rename the levels was the
> original question.
>
> Uwe

I don't want to rename levels or converting from numeric to string. I
want to add each corresponding levels value, a label, as in SPSS.
Level 0 labeled with alive,
level 1 labeled with dead and
level 2 labeled with missed.


This is not possible with a factor, because factor levels can only be 
positive integers.


That is just plain (ridiculously) wrong. RTFM.

cheers,

Rolf Turner

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

2011-08-11 Thread Eleanor Spratt
I am using two mixed effect models. Firstly, what I am trying to do is to
compare green roofs abundance with brownfield, green roof with green space
abundance, and finally green
space with brownfield abundance. I am unsure if I have done the
correct model. I have to use a mixed effect model because my data is
nested.

This is the code and output

> model1<-lmer(Total.abundance~Habitat+(1|Site)+(1|Week),REML=FALSE,family=poisson)
> summary(model1)

Generalized linear mixed model fit by the Laplace approximation
Formula: Total.abundance ~ Habitat + (1 | Site) + (1 | Week)
 AIC  BIC logLik deviance
 1780 1795 -884.9 1770
Random effects:
 Groups NameVariance Std.Dev.
 Site   (Intercept) 0.62318  0.78941
 Week   (Intercept) 0.13883  0.37260
Number of obs: 150, groups: Site, 15; Week, 10

Fixed effects:
  Estimate Std. Error z value Pr(>|z|)
(Intercept)  2.8116 0.3740   7.517 5.59e-14 ***
HabitatGreen roof   -0.8676 0.5040  -1.721   0.0852 .
HabitatGreen space   0.2008 0.5021   0.400   0.6892
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
   (Intr) HbttGr
HabittGrnrf -0.668
HabttGrnspc -0.671  0.498

>From this I understand that green roof has a negative trend with
brownfield, and green space has no significance with brownfield. But
what about green roof and green space Is there a way of
interpreting this information from the above data. Is it like ANOVA
where you have to manually calculate the p value. Or do I have to
simplify this model by reducing my Habitat factors levels (e.g.
combining green space and brownfield together).

My second mixed effect model is seeing if environmental factors influence
the mixed effect model, but I want to use interactions. When I plot this I
get an error message.

> model1<-lmer(Total.abundance~(area+Hemeroby+Age+isolation+Height+Bare.ground+Grass+Non.grass)^2+(1|Site)+(1|Week),REML=FALSE,family=poisson)

Error: inner loop 1; cannot correct step size
In addition: Warning message:
step size truncated due to divergence 

Thus I tried it without interactions- 
> model1<-lmer(Total.abundance~area+Hemeroby+Age+isolation+Height+Bare.ground+Grass+Non.grass+(1|Site)+(1|Week),REML=FALSE,family=poisson)

but with a couple of simplifications of the model the intercept was not
significant, so I dont' know what to do.

Kind Regards

Ellie

--
View this message in context: 
http://r.789695.n4.nabble.com/Mixed-effect-models-tp3737266p3737266.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] Removing all duplicate row except by one

2011-08-11 Thread m.marcinmichal
Hi,
It's my problem, supppose that we have a data.frame:

t
  a b c
1 1 1 1
2 0 1 1
3 1 1 1
4 0 0 0
5 1 0 1
6 0 1 0
7 1 1 1
8 0 1 0

I need extract duplicat row i.e i nedd frame like this

  a b c
3 1 1 1
8 0 1 0

I try use subset(t, duplicated(t)) and t[duplicated(t), ] but this command
return

  a b c
3 1 1 1
7 1 1 1
8 0 1 0

Best

Marcin M.


--
View this message in context: 
http://r.789695.n4.nabble.com/Removing-all-duplicate-row-except-by-one-tp3736949p3736949.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] sapply( ) a loop function

2011-08-11 Thread Sean Bignami
Hello R-universe...

I am having trouble writing a function which contains a loop so I can sapply() 
it to a list of data frames

Each data frame has 241 observations of 15 variables. My loop takes a random 
sample of one row until the 40 consecutive rows after the sample have a 
d2p(variable) sum greater than 5.

here is my loop code (it works fine when applied to a 241 observation data 
frame):

n<-241
test<-0
while(test<5){
i<-sample(1:n-40,1)
x<-my.data.frame[seq(from=i, to=i+40),]
test<-sumx[,"d2p"],na.rm=TRUE)
}; i ; test

I need this loop to be applied to EACH DATA FRAME in a list of 360 data frames 
created by splitting my master data frame, d, by each fish number. (contains 
observations for 360 fish, each with 241 observations of 15 variables).

split.df<-split(d,d$fish)

I'm kind of new at writing functions, so I'm sure this probably doesn't make 
much sense, but here is what I tried for the function:

samp.func<-function(f) {
n<-241
test<-0
while(test<5){
i<-sample(1:n-40,1)
x<-f[seq(from=i, to=i+40),]
test<-sum(x[,"d2p"],na.rm=TRUE)
}}

and then tried to apply it to my list of data frames (NOT WORKING):

sapply(split.df,samp.func)

I'm pretty sure I'm missing some way to instruct that I want the loop to cycle 
through for each item (data frame) in my split.df list. I've tried to play 
around with including "for" loops with no avail...

any ideas?



here is code for a simplified mock single-fish data frame (i.e. one item in my 
split.df list) to plug into the loop if you want to try it. 

fish<-rep(1,241)
d2p<-seq((50/241),50,(50/241))
my.data.frame<-data.frame(fish,d2p)

thanks!!
Sean


[[alternative HTML version deleted]]

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


Re: [R] value.labels

2011-08-11 Thread Heinz Tuechler

At 11.08.2011 21:50 +0300, Zeki Çatav wrote:

Prş, 2011-08-11 tarihinde 19:27 +0200 saatinde, Uwe Ligges yazdı:
>
> On 11.08.2011 19:22, David Winsemius wrote:
> >
> > On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:
> >
> >>
> >>
> >> On 11.08.2011 16:10, zcatav wrote:
> >>> Hello R people,
> >>>
> >>> I have a "data.frame". Status variable has 3 values. 0->alive,
> >>> 1->dead and
> >>> 2->missed..
> .
> As I understood the question, just how to rename the levels was the
> original question.
>
> Uwe

I don't want to rename levels or converting from numeric to string. I
want to add each corresponding levels value, a label, as in SPSS.
Level 0 labeled with alive,
level 1 labeled with dead and
level 2 labeled with missed.


This is not possible with a factor, because 
factor levels can only be positive integers.


Heinz




--
Zeki Çatav


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

2011-08-11 Thread Liviu Andronic
On Wed, Aug 10, 2011 at 11:39 PM, David Winsemius
 wrote:
>> is.vector(x)
> [1] TRUE
>
> You probably didn't realize that lists _are_ vectors before this.
>
Nice to know.


> Hopefully this expected invitation to grilling will not result in severe
> burns. I note that one of the *apply family would have been successful in
> returning the desired object in conjunction with c() :
>
>> rapply(x, c)
>  [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l"
>
> `rapply` is designed to do a complete traversal of the list structure and
> its default "how" argument is "unlist". It was linked from the page where
> you were looking at `simplify2array`.
>
This also does the job nicely. As does

> c(x, recursive=T)
 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l"

per Peter's suggestion. Thanks all for all the solutions.

Regards
Liviu

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


Re: [R] 2-dim density plot

2011-08-11 Thread annie Zhang
Thank you so much, Michael and Duncan. It worked.

Annie

On Thu, Aug 11, 2011 at 2:23 PM, Duncan Murdoch wrote:

>  On 11/08/2011 3:11 PM, annie Zhang wrote:
>
>> Hi All,
>>
>> I have a 2-dim density defined on 0> formula of the density. How can I visualize it? What plot functions can I
>> use?
>>
>
>
> persp() or contour() are in the graphics package.  There are similar ones
> in lattice (and I think in ggplot2), but I forget their names.  There's also
> persp3d() in the rgl package for a rotatable version of persp().
>
> Supposing f(x,y) gives the density at (x,y) (or NA if x > y), you plot it
> as follows:
>
> x <- seq(0, 1, len=30)
> y <- seq(0, 1, len=30)
> z <- outer(x, y, f)
> persp(x,y,z)
> contour(x,y,z)
> persp3d(x,y,z)
>
> This relies on f() being vectorized; if it's not, use
>
> z <- outer(x,y, Vectorize(f))
>
> instead.
>
> Duncan Murdoch
>

[[alternative HTML version deleted]]

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


Re: [R] help with loops

2011-08-11 Thread William Dunlap
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf Of R. Michael
> Weylandt
> Sent: Thursday, August 11, 2011 10:09 AM
> To: Srinivas Iyyer
> Cc: r-help@r-project.org
> Subject: Re: [R] help with loops
> 
> No problem,
> 
> By the way, you can't (or at least shouldn't) use return() outside of a
> function -- that was the source of your old error message.
> 
> If you, for whatever reason, couldn't use unlist() you would write:
> 
> OurUnlist <- function(c, unique = F) {
>   if (!is.list(c)) return(c)
>   z <- NULL
>   for (i in seq_along(c)) {
>z <- c(z,c[[i]])
>   }
>   if (unique) return(unique(z))
>   return(z)
> }
> 
> or some such. Still, I suggest you stick with built in functions whenever
> possible.

I tend to encourage people to write functions.

I suppose you may end up reinventing the wheel,
but once you get used to writing functions it
is often faster to write a specialized one than
to find one that meets your needs.  When you
discover a new idiom for your task (e.g., calling
unlist() instead of the for loop), you just edit
one function (OurUnlist) instead of editing all
your scripts that used the old idiom).

Once you get used to writing functions (and using
them), you are ready to document them and package
them up for others to use.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

> 
> Michael Weylandt
> 
> PS -- Can you email me (off list) and let me know what this is for? We've
> been asked this question a couple of times over the last few days and I'm
> just wondering why it's a calculation of interest to so many.
> 
> On Thu, Aug 11, 2011 at 1:00 PM, Srinivas Iyyer
> wrote:
> 
> > Thank you. that was very easy.
> > -srini
> >
> > --- On *Thu, 8/11/11, R. Michael Weylandt 
> > *wrote:
> >
> >
> > From: R. Michael Weylandt 
> > Subject: Re: [R] help with loops
> > To: "Srinivas Iyyer" 
> > Cc: r-help@r-project.org
> > Date: Thursday, August 11, 2011, 12:49 PM
> >
> >
> > unlist()
> >
> > Michael Weylandt
> >
> > On Thu, Aug 11, 2011 at 12:46 PM, Srinivas Iyyer <
> > srini_iyyer_...@yahoo.com 
> > > wrote:
> >
> > hi I need help with list object.
> >
> > I have a list object
> >
> > > a <- c('apple','orange','grape')
> > > b <- c('car','truck','jeep')
> > > c <- list(a,b)
> > > names(c) <- c('fruit','vehicle')
> > > c
> > $fruit
> > [1] "apple"  "orange" "grape"
> >
> > $vehicle
> > [1] "car"   "truck" "jeep"
> >
> >
> > I want to write all the elements of this list in one object 'z'.
> >
> > >z
> > [1] "apple"  "orange" "grape" "car"   "truck" "jeep"
> >
> > How can I write the elements of c to z
> > I tried using a for loop. Could any one help me please. thanks
> >
> >
> > > z <- ''
> > > for (i in 1:length(c)){
> > + k <- c[[i]]
> > + z <- c(z,k)
> > + return(z)}
> > Error: no function to return from, jumping to top level
> > >
> >
> >
> > Thank you.
> > srini
> >
> > __
> > R-help@r-project.org  mailing
> > list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> >
> >
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] help with loops

2011-08-11 Thread R. Michael Weylandt
No problem,

By the way, you can't (or at least shouldn't) use return() outside of a
function -- that was the source of your old error message.

If you, for whatever reason, couldn't use unlist() you would write:

OurUnlist <- function(c, unique = F) {
  if (!is.list(c)) return(c)
  z <- NULL
  for (i in seq_along(c)) {
   z <- c(z,c[[i]])
  }
  if (unique) return(unique(z))
  return(z)
}

or some such. Still, I suggest you stick with built in functions whenever
possible.

Michael Weylandt

PS -- Can you email me (off list) and let me know what this is for? We've
been asked this question a couple of times over the last few days and I'm
just wondering why it's a calculation of interest to so many.

On Thu, Aug 11, 2011 at 1:00 PM, Srinivas Iyyer
wrote:

> Thank you. that was very easy.
> -srini
>
> --- On *Thu, 8/11/11, R. Michael Weylandt *wrote:
>
>
> From: R. Michael Weylandt 
> Subject: Re: [R] help with loops
> To: "Srinivas Iyyer" 
> Cc: r-help@r-project.org
> Date: Thursday, August 11, 2011, 12:49 PM
>
>
> unlist()
>
> Michael Weylandt
>
> On Thu, Aug 11, 2011 at 12:46 PM, Srinivas Iyyer <
> srini_iyyer_...@yahoo.com 
> > wrote:
>
> hi I need help with list object.
>
> I have a list object
>
> > a <- c('apple','orange','grape')
> > b <- c('car','truck','jeep')
> > c <- list(a,b)
> > names(c) <- c('fruit','vehicle')
> > c
> $fruit
> [1] "apple"  "orange" "grape"
>
> $vehicle
> [1] "car"   "truck" "jeep"
>
>
> I want to write all the elements of this list in one object 'z'.
>
> >z
> [1] "apple"  "orange" "grape" "car"   "truck" "jeep"
>
> How can I write the elements of c to z
> I tried using a for loop. Could any one help me please. thanks
>
>
> > z <- ''
> > for (i in 1:length(c)){
> + k <- c[[i]]
> + z <- c(z,k)
> + return(z)}
> Error: no function to return from, jumping to top level
> >
>
>
> Thank you.
> srini
>
> __
> R-help@r-project.org  mailing
> list
> https://stat.ethz.ch/mailman/listinfo/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] 2-dim density plot

2011-08-11 Thread Duncan Murdoch

On 11/08/2011 3:11 PM, annie Zhang wrote:

Hi All,

I have a 2-dim density defined on 0


persp() or contour() are in the graphics package.  There are similar 
ones in lattice (and I think in ggplot2), but I forget their names.  
There's also persp3d() in the rgl package for a rotatable version of 
persp().


Supposing f(x,y) gives the density at (x,y) (or NA if x > y), you plot 
it as follows:


x <- seq(0, 1, len=30)
y <- seq(0, 1, len=30)
z <- outer(x, y, f)
persp(x,y,z)
contour(x,y,z)
persp3d(x,y,z)

This relies on f() being vectorized; if it's not, use

z <- outer(x,y, Vectorize(f))

instead.

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] 2-dim density plot

2011-08-11 Thread R. Michael Weylandt
I'd suggest either a color plot as given by image() and related functions or
a 3d mesh-plot which you can get from persp()

E.g.,

x = seq(0,1,by=0.01); y = x
z = outer(x,y+1,"/") # z = x/(y+1) -- I know that's not a density but you
can adapt as necessary

filled.contour(x,y,z)
persp(x,y,z)

There are many more functions like this available, but here's a start.

Good luck!

Michael Weylandt

On Thu, Aug 11, 2011 at 3:11 PM, annie Zhang wrote:

> Hi All,
>
> I have a 2-dim density defined on 0 formula of the density. How can I visualize it? What plot functions can I
> use?
>
> Thanks,
> Annie
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] 2-dim density plot

2011-08-11 Thread annie Zhang
Hi All,

I have a 2-dim density defined on 0https://stat.ethz.ch/mailman/listinfo/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] Weighted data with npcdensbw

2011-08-11 Thread Barnet Wagman

Is there a way of using weighted data with npcdensbw (in the np package)?

thanks

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


Re: [R] value.labels

2011-08-11 Thread Bert Gunter
Use factor -- puhleeze read the Help file therefor:

factor(x = character(), levels, labels = levels,
   exclude = NA, ordered = is.ordered(x))

either an optional vector of labels for the levels (in the same order
as levels after removing those in exclude), or a character string of
length 1.

-- Bert

2011/8/11 Zeki Çatav :
> Prş, 2011-08-11 tarihinde 19:27 +0200 saatinde, Uwe Ligges yazdı:
>>
>> On 11.08.2011 19:22, David Winsemius wrote:
>> >
>> > On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:
>> >
>> >>
>> >>
>> >> On 11.08.2011 16:10, zcatav wrote:
>> >>> Hello R people,
>> >>>
>> >>> I have a "data.frame". Status variable has 3 values. 0->alive,
>> >>> 1->dead and
>> >>> 2->missed..
>> .
>> As I understood the question, just how to rename the levels was the
>> original question.
>>
>> Uwe
>
> I don't want to rename levels or converting from numeric to string. I
> want to add each corresponding levels value, a label, as in SPSS.
> Level 0 labeled with alive,
> level 1 labeled with dead and
> level 2 labeled with missed.
>
>
>
> --
> Zeki Çatav
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



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

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics

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


Re: [R] value.labels

2011-08-11 Thread Zeki Çatav
Prş, 2011-08-11 tarihinde 19:27 +0200 saatinde, Uwe Ligges yazdı:
> 
> On 11.08.2011 19:22, David Winsemius wrote:
> >
> > On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:
> >
> >>
> >>
> >> On 11.08.2011 16:10, zcatav wrote:
> >>> Hello R people,
> >>>
> >>> I have a "data.frame". Status variable has 3 values. 0->alive,
> >>> 1->dead and
> >>> 2->missed..
> .
> As I understood the question, just how to rename the levels was the 
> original question.
> 
> Uwe

I don't want to rename levels or converting from numeric to string. I
want to add each corresponding levels value, a label, as in SPSS.
Level 0 labeled with alive,
level 1 labeled with dead and
level 2 labeled with missed.



-- 
Zeki Çatav


signature.asc
Description: Bu dijital olarak imzalanmış ileti parçasıdır
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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() a data frame containing 'character' variables?

2011-08-11 Thread Liviu Andronic
On Wed, Aug 10, 2011 at 5:52 PM, Jean V Adams  wrote:
> data.frame(lapply(x, function(y) if(is.numeric(y)) round(y, 2) else y))
>
Building on this, I came up with a 'data.frame' method for round().
I'm not sure how orthodox it is, but it seems to do the job as
intended:
round.data.frame <-
function(x, digits = 0)
{
data.frame(lapply(x, function(y) if(is.numeric(y)) round(y, digits) else y))
}

Here's an example:
> set.seed(2)
> x <- data.frame(a=rnorm(10), b=rnorm(10), c=rnorm(10), d=letters[1:10])
> print(x, digits=2)  ##it displays 2, 3 or 4 digits, instead of the desired 2
   a  b   c d
1  -0.90  0.418  2.0908 a
2   0.18  0.982 -1.1999 b
3   1.59 -0.393  1.5896 c
4  -1.13 -1.040  1.9547 d
5  -0.08  1.782  0.0049 e
6   0.13 -2.311 -2.4517 f
7   0.71  0.879  0.4772 g
8  -0.24  0.036 -0.5966 h
9   1.98  1.013  0.7922 i
10 -0.14  0.432  0.2896 j
> round(x, 2)
   a b c d
1  -0.90  0.42  2.09 a
2   0.18  0.98 -1.20 b
3   1.59 -0.39  1.59 c
4  -1.13 -1.04  1.95 d
5  -0.08  1.78  0.00 e
6   0.13 -2.31 -2.45 f
7   0.71  0.88  0.48 g
8  -0.24  0.04 -0.60 h
9   1.98  1.01  0.79 i
10 -0.14  0.43  0.29 j

Would such a method get any chance of inclusion in 'base'? Regards
Liviu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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() a data frame containing 'character' variables?

2011-08-11 Thread Liviu Andronic
On Thu, Aug 11, 2011 at 4:58 PM, David Winsemius  wrote:
>>> numVars <- sapply(iris, is.numeric)
>>> iris[numVars] <- lapply(iris[numVars], round, digits = 2)
>>> head(iris)
>>>
> Then drop the assignment operation and just print:
>
> ( lapply(iris[numVars], round, digits = 2) )
>
That's a nice catch, thanks. The only problem with this approach is
that non-numeric variables are simply discarded, while I would prefer
for them to be simply ignored.


> Or set your digits argument to print:
>
> print( head(iris), digits=1)
>
> Or did I miss something?
>
As I explained in today's reply to Martin, print(..., digits = 2) and
format(..., digits = 2) both display a "minimal number of
_significant_ digits". However, for various reasons, I need to specify
the "number of decimal places" as in round(..., digits = 2). Both
print() and format() don't provide an obvious way to do that.

Regards
Liviu

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


Re: [R] model formula

2011-08-11 Thread Eik Vettorazzi


Am 11.08.2011 17:39, schrieb Uwe Ligges:
> 
> 
> On 11.08.2011 17:27, Bond, Stephen wrote:
>> Hello useRs,
>>
>> Pls help with removing a single interaction term from a formula:
>>
>> summary(
>>  glm.turn.2<-
>> glm(cbind(turn.cnt,tot.cnt-turn.cnt)~sn+poly(relAge,2,raw=T)+termfac+rate:termfac,data=fix,
>>
>>family="quasibinomial")
>>  )
>>
>> Gives
>>
>> Coefficients:
>> Estimate Std. Error t value Pr(>|t|)
>> (Intercept)   -7.028467   0.106002 -66.305<  2e-16 ***
>> snFeb  0.156963   0.023660   6.634 3.27e-11 ***
>> snMar  0.317540   0.022883  13.876<  2e-16 ***
>> snApr  0.526084   0.022004  23.908<  2e-16 ***
>> snMay  1.026710   0.020347  50.460<  2e-16 ***
>> snJun  0.841044   0.021318  39.452<  2e-16 ***
>> snJul  0.668790   0.022530  29.685<  2e-16 ***
>> snAug  0.544267   0.022580  24.104<  2e-16 ***
>> snSep  0.389667   0.023363  16.679<  2e-16 ***
>> snOct  0.351294   0.023586  14.894<  2e-16 ***
>> snNov  0.391464   0.024057  16.272<  2e-16 ***
>> snDec -0.373369   0.028755 -12.985<  2e-16 ***
>> poly(relAge, 2, raw = T)1  2.952887   0.067455  43.776<  2e-16 ***
>> poly(relAge, 2, raw = T)2 -1.783907   0.064074 -27.841<  2e-16 ***
>> termfac2  -0.681719   0.128571  -5.302 1.14e-07 ***
>> termfac3  -1.032416   0.146396  -7.052 1.77e-12 ***
>> termfac4  -1.267011   0.108940 -11.630<  2e-16 ***
>> termfac5  -1.009922   0.213129  -4.739 2.15e-06 ***
>> termfac6   3.300301   0.203465  16.221<  2e-16 ***
>> termfac1:rate  0.012274   0.019895   0.6170.537
>> termfac2:rate  0.121724   0.013472   9.036<  2e-16 ***
>> termfac3:rate  0.175232   0.018987   9.229<  2e-16 ***
>> termfac4:rate  0.197726   0.005787  34.164<  2e-16 ***
>> termfac5:rate  0.145622   0.027295   5.335 9.56e-08 ***
>> termfac6:rate -0.362379   0.025261 -14.345<  2e-16 ***
>>
>> and I would like to remove the termfac1:rate interaction. Is there a
>> way to do that?
>> Thank you
> 
> And what do you want to do with the observations with termfac=1 then?
> Ignore? Also move to the Intercept?

Actually they are already in the Intercept because of the treatment
contrasts. The crucial part in the glm formula above is
 termfac+rate:termfac
which specifies intercepts deviating from termfac1 level and slopes for
every level of termfac. A dummy coding for different slopes should work,
since the slopes are independently modelled and tested against 0.


> 
> Uwe Ligges
> 
> 
> 
>>
>> Stephen Bond
>>
>>
>> [[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.

-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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() a data frame containing 'character' variables?

2011-08-11 Thread Liviu Andronic
Hello

On Thu, Aug 11, 2011 at 4:34 PM, Martin Maechler
 wrote:
> Well, as you say it's  "View()" only, so why don't you just
> "view" the result of
>
> something like
>          print(, digits = 2)
>
Unfortunately print(..., digits = 2) suffers of the same deficiencies
as format(..., digits = 2): they both display a "minimal number of
_significant_ digits". What I would need, however, is to specify the
"number of decimal places" as in round(..., digits = 2).


> (it does correspond to  signif(), rather than round(),
>  but I think that that's more sensible anyway).
>
Although I do appreciate the rationale behind ?signif, for several
subjective reasons---easiness of inspecting round()-ed data or
aesthetics in printing round()-ed data in Sweave (as in "I cannot send
format()-ed data to my advisor")---I would prefer to ?round my data.

Is there any chance that 'base' would feature a round() function that
doesn't stumble when processing non-numeric data (simply by ignoring
it), or a format() or print() function with a 'round=NULL' argument?

Regards
Liviu

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


Re: [R] generate two sets of random numbers that are correlated

2011-08-11 Thread Duncan Murdoch

On 11/08/2011 1:33 PM, Duncan Murdoch wrote:

On 11/08/2011 12:01 PM, Kathie wrote:
>  almost forgot. In fact, I want to generate correlated Poisson random vectors.

Saying you want two random variables to be correlated doesn't specify
the joint distribution, so there will be a lot of solutions.  Here's
one, for the case where both variables have the same mean mu, and you
want a positive correlation.

We know that the sum of independent Poissons is Poisson, so we'll
generate 3 variables: X with mean nu, and Y&  Z with mean mu-nu, and return
A = X+Y and B = X+Z.  If nu=0 then A and B are independent, and if
nu=mu, they have correlation 1, so you must be able to solve for a value
where they have any desired correlation in between.

If the means aren't the same, this method will still work up to a point,
but you won't be able to get really high correlations.

If you want negative correlations it's harder, but you could use the
following trick:  Generate U ~ Unif(0, 1).  Calculate A by the inverse
CDF method from U.  Compute V to be equal to U if U<  a or U>  1-a, and
equal to 1-U otherwise.  Calculate B by the inverse CDF method on V.

Then both U and V will have Poisson distributions (and you can choose


I meant A and B in the line above...


the means as you like), and there will be some range of achievable
correlations which will be quite close to [-1, 1].  The joint
distribution will be very weird, but you didn't say that was a problem...

Some R code:

U<- runif(1)
A<- qpois(U, 5)
a<- 0.115
V<- ifelse(U<  a | U>  1-a, U, 1-U)
B<- qpois(V, 5)
cor(A, B)

This gives a correlation around 0.4.


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] generate two sets of random numbers that are correlated

2011-08-11 Thread Albyn Jones
Here is a simple method

z1 <- rpois(n,mu1)
z2 <- rpois(n,mu1)
z3 <- rpois(n,mu2)

Y <- z1 + z3
X <- z2 + z3

Cov(X,Y) = mu2, so Cor(X,Y) = mu2/(mu1+mu2)

albyn

On Thu, Aug 11, 2011 at 09:01:50AM -0700, Kathie wrote:
> almost forgot. In fact, I want to generate correlated Poisson random vectors.
> Thank you anyway
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/generate-two-sets-of-random-numbers-that-are-correlated-tp3736161p3736287.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.
> 

-- 
Albyn Jones
Reed College
jo...@reed.edu

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


Re: [R] generate two sets of random numbers that are correlated

2011-08-11 Thread Duncan Murdoch

On 11/08/2011 12:01 PM, Kathie wrote:

almost forgot. In fact, I want to generate correlated Poisson random vectors.


Saying you want two random variables to be correlated doesn't specify 
the joint distribution, so there will be a lot of solutions.  Here's 
one, for the case where both variables have the same mean mu, and you 
want a positive correlation.


We know that the sum of independent Poissons is Poisson, so we'll 
generate 3 variables: X with mean nu, and Y & Z with mean mu-nu, and return
A = X+Y and B = X+Z.  If nu=0 then A and B are independent, and if 
nu=mu, they have correlation 1, so you must be able to solve for a value 
where they have any desired correlation in between.


If the means aren't the same, this method will still work up to a point, 
but you won't be able to get really high correlations.


If you want negative correlations it's harder, but you could use the 
following trick:  Generate U ~ Unif(0, 1).  Calculate A by the inverse 
CDF method from U.  Compute V to be equal to U if U < a or U > 1-a, and 
equal to 1-U otherwise.  Calculate B by the inverse CDF method on V.


Then both U and V will have Poisson distributions (and you can choose 
the means as you like), and there will be some range of achievable 
correlations which will be quite close to [-1, 1].  The joint 
distribution will be very weird, but you didn't say that was a problem...


Some R code:

U <- runif(1)
A <- qpois(U, 5)
a <- 0.115
V <- ifelse(U < a | U > 1-a, U, 1-U)
B <- qpois(V, 5)
cor(A, B)

This gives a correlation around 0.4.


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] round() a data frame containing 'character' variables?

2011-08-11 Thread Liviu Andronic
On Wed, Aug 10, 2011 at 5:52 PM, Jean V Adams  wrote:
>
> As it says in
>
> ?format
>
> the digits argument specifies "... how many significant digits are to be
> used ... enough decimal places will be used so that the smallest (in
> magnitude) number has this many significant digits ..."
>
> In your example, the last value in column "a" is 0.06348058 which is written
> as 0.063 to two significant digits.
>
I did inspect the help page (several times), but the "significant
digits" formulation was a little too cryptic to me. Now I understand
better, thanks.


> There is no way (that I know of) to make the format() function do the same
> sort of thing as round().
>
> If digits won't meet your needs, you could try something like this
>
> data.frame(lapply(x, function(y) if(is.numeric(y)) round(y, 2) else y))
>
Quite awkward, but this is more or less what I was looking for. Again, thanks.

Regards
Liviu

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


Re: [R] value.labels

2011-08-11 Thread Uwe Ligges



On 11.08.2011 19:22, David Winsemius wrote:


On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:




On 11.08.2011 16:10, zcatav wrote:

Hello R people,

I have a "data.frame". Status variable has 3 values. 0->alive,
1->dead and
2->missed
Status as a factor have correct levels. Levels and labels output as
follows;

levels(Adbf$status); labels(Adbf$status)
[1] "0" "1" "2"
[1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10"
[11] "11" "12" "13" "14" "15" "16" "17" "18" "19" "20"
[21] "21" "22" "23" "24" "25" "26" "27" "28" "29" "30"
[31] "31" "32" "33" "34" "35" "36" "37" "38" "39" "40"
[41] "41" "42" "43" "44" "45" "46" "47" "48" "49" "50"

"644"


Can i add value.labels to status variable? If yes how? Can i see these
value.labels on results or graphics?



levels(Adbf$status) <- c("alive", "dead", "missed")


I'm probably making some mistake, but my efforts to use something
similar to that construction have caused me to "destroy" variables in
the sense that I have made them all NA's. My more (defensive?,
unnecessary?) practice has become:

Adbf$status <- factor( Adbf$status, labels= c("alive", "dead", "missed") )

When I try to use the `levels<-' operation now on what I think is a
similar object, I get an error but maybe that relates to the fact that
levels and labels are different?

 > status <- factor( sample(1:50, 400, replace=TRUE) )
 > status <- status[status %in% c("1", "2", "3")]
 > str(status)
Factor w/ 50 levels "1","2","3","4",..: 3 3 1 1 2 2 2 2 1 1 ...


Errr, this should have 3 levels, "0", "1", "2", actually.


 > length(status)
[1] 24
 > levels(status) <- c("alive", "dead", "missed")
Error in `levels<-.factor`(`*tmp*`, value = c("alive", "dead", "missed" :
number of levels differs

The real question I have as a follow-on is what is the "right way" to
take an object like this:

levels(testres) <- c(levels(testres), "NotDone")
 > testres
[1] 1 2 3 
Levels: 1 2 3 NotDone

... and add a not done label?

These do not "work":
#1:
 > levels(testres) <- c("NotDone", levels(testres))
 > testres[4]
[1] 
Levels: NotDone 1 2 3

#2:
 > testres <- factor(c(1,2,3,NA))
 > levels(testres) <- c(levels(testres), "NotDone")
 > testres[4]
[1] 
Levels: 1 2 3 NotDone

I have been converting to numeric, changing NA to 0 and then refactoring
with labels=c("Not done", levels(old_factor) ), but that seems B(a)roke.


Hmm, when you want to add a level without changing the class of the 
factor object, you will have to add the level at first and then assign 
the level to the elements of the object. I'd probably rebuild the whole 
thing in that case.


As I understood the question, just how to rename the levels was the 
original question.


Uwe

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


Re: [R] value.labels

2011-08-11 Thread David Winsemius


On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:




On 11.08.2011 16:10, zcatav wrote:

Hello R people,

I have a "data.frame". Status variable has 3 values. 0->alive, 1- 
>dead and

2->missed
Status as a factor have correct levels. Levels and labels output as  
follows;


levels(Adbf$status); labels(Adbf$status)
[1] "0" "1" "2"
  [1] "1"   "2"   "3"   "4"   "5"   "6"   "7"   "8"   "9"   "10"
 [11] "11"  "12"  "13"  "14"  "15"  "16"  "17"  "18"  "19"  "20"
 [21] "21"  "22"  "23"  "24"  "25"  "26"  "27"  "28"  "29"  "30"
 [31] "31"  "32"  "33"  "34"  "35"  "36"  "37"  "38"  "39"  "40"
 [41] "41"  "42"  "43"  "44"  "45"  "46"  "47"  "48"  "49"  "50"

"644 
"


Can i add value.labels to status variable? If yes how? Can i see  
these

value.labels on results or graphics?



levels(Adbf$status) <- c("alive", "dead", "missed")


I'm probably making some mistake, but my efforts to use something  
similar to that construction have caused me to "destroy" variables in  
the sense that I have made them all NA's. My more (defensive?,  
unnecessary?)  practice has become:


 Adbf$status <- factor( Adbf$status, labels= c("alive", "dead",  
"missed") )


When I try to use the `levels<-' operation now on what I think is a  
similar object, I get an error but maybe that relates to the fact that  
levels and labels are different?


> status <- factor( sample(1:50, 400, replace=TRUE)  )
> status <- status[status %in% c("1", "2", "3")]
> str(status)
 Factor w/ 50 levels "1","2","3","4",..: 3 3 1 1 2 2 2 2 1 1 ...
> length(status)
[1] 24
> levels(status) <- c("alive", "dead", "missed")
Error in `levels<-.factor`(`*tmp*`, value = c("alive", "dead",  
"missed" :

  number of levels differs

The real question I have as a follow-on is what is the "right way" to  
take an object like this:


levels(testres) <- c(levels(testres), "NotDone")
> testres
[1] 123
Levels: 1 2 3 NotDone

... and add a not done label?

These do not "work":
#1:
> levels(testres) <- c("NotDone", levels(testres))
> testres[4]
[1] 
Levels: NotDone 1 2 3

#2:
> testres <- factor(c(1,2,3,NA))
> levels(testres) <- c(levels(testres), "NotDone")
> testres[4]
[1] 
Levels: 1 2 3 NotDone

I have been converting to numeric, changing NA to 0 and then  
refactoring with labels=c("Not done", levels(old_factor) ), but that  
seems B(a)roke.



--

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] generate two sets of random numbers that are correlated

2011-08-11 Thread Kathie
almost forgot. In fact, I want to generate correlated Poisson random vectors.
Thank you anyway

--
View this message in context: 
http://r.789695.n4.nabble.com/generate-two-sets-of-random-numbers-that-are-correlated-tp3736161p3736287.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] Subsampling data

2011-08-11 Thread Eik Vettorazzi
Hi Stefán
you might not to see the wood for the trees, but ?subset is a R function
as well.
MalesData <- subset(Datatemp,Datatemp$sex==1)

btw. your selection
> MalesData <- Datatemp[Datatemp $sex==1]

went wrong for two reasons:
(a) the extra space befor $
(b) incorrect indexing. Datatemp is a data.frame and has 2 dimensions
(and to my surprise indexing on one dimension only returns the
respective columns, which is different from matrix indexing), so
MalesData <- Datatemp[Datatemp$sex==1,]

should work as well.


Am 11.08.2011 16:16, schrieb Stefán Hrafn Jónsson:
> *Dear R community*
> 
> * *
> 
> *I have two questions on data subsample manipulation. I am starting to use R
> again after a long brake  and feel a bit rusty.*
> 
> * *
> 
> *I want to select a subsample of data for males and females separately*
> 
> * *
> 
> 
> 
> library(foreign)
> 
> Datatemp  <- read.spss("H:/Skjol/Data/HL/t1and2b.sav", use.value.labels = F)
> 
> 
> 
> 
> 
> 
>> table(Datatemp$sex)
> 
> 
> 
>12
> 
> 3049 3702
> 
> 
> 
>> attributes(Datatemp)
> 
> …
> 
> $names
> 
>  [1] "nomiss""Bin"   "rad09" "year"
> "sex"
> "income""adults"
> 
>  [8] "children"  "student"   "retired"   "disabled"
> "homemaker" "unemployed""employed"
> 
> [15] "occupation""residencysize" "educ"  "agemean"
> "age"
> "marital"
> 
> 
> 
> $codepage
> 
> [1] 1252
> 
> 
> 
>> MalesData <- Datatemp[Datatemp $sex==1]
> 
>> MalesData
> 
> named list()
> 
>> attributes(MalesData)
> 
> $names
> 
> character(0)
> 
> 
> 
> 
> Females.Data <- Datatemp[Datatemp $sex==2]
> 
> 
> 
> 
> 
> 
> 
> *This subset extraction is not working. Is there anyone who can tell me what
> I did wrong?*
> 
> * *
> 
> * *
> 
> *A different but related question is the use of the function paste or if I
> need another function to do the following: *
> 
> * *
> 
> * *
> 
> *Rather than this*:
> 
> 
> 
>> m2 <- gee( Bin ~  agemean +  year,  id = rad09 , data = datause ,
> subset=kyn== 1 ,
> 
>family =  binomial, corstr ="exchangeable" )
> 
> 
> 
> 
> 
> 
> 
> *I want to do this (modified in  a loop). *
> 
> 
> 
> 
> 
>> subsampl <- "kyn== 1 "
> 
> 
> 
>> m2 <- gee( Bin ~  agemean +  year,  id = rad09 , data = datause ,
> subset=paste(subsampl) ,
> 
>family =  binomial, corstr ="exchangeable" )
> 
> 
> 
> Beginning Cgee S-function, @(#) geeformula.q 4.13 98/01/27
> 
> Error in gee(Bin ~ agemean + year, id = rad09, data = datause, subset =
> paste(subsampl),  :
> 
>   rank-deficient model matrix
> 
> 
> 
> 
> 
> 
> 
> *I hope you can see what I want to do, but I think I may need other function
> than paste()*
> 
> *
> *
> 
> *I appreciate a lot any help. *
> 
> *
> Stefan Hrafn*
> 
>   [[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.

-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

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


Re: [R] step

2011-08-11 Thread Uwe Ligges

On 03.08.2011 16:33, Diana Schwegler wrote:

Hello I am using the "step" function in order to do backward selection for a
linear model of more than 200 variables but it doesn't work correctly.
I think, there is a problem, if the matrix has same or more columns than
rows.
And if the matrix has too much columns the step-function doesn't work
because the function will work with all columns together and I think, this
is
the problem.
Is there a solution or a bug fixing of this problem?


If you reinvent the methodology.

Please read some textbook about linear models and how much sense a 
stepwise selection makes if you have so many variables that may be 
highly correlated etc


Note that you do not have any degrees of freedom left for fitting the 
whole model. And that is required if you are aiming at a stepwise 
backward selection.


Uwe Ligges






Thanks a lot

--
View this message in context: 
http://r.789695.n4.nabble.com/step-tp3715681p3715681.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] Cv.glment question -- why giving me an error

2011-08-11 Thread Andra Isan
Hi All, 
I am trying to run cv.glmnet(x,y,family="multinomial", nfolds =4) and I only 
have 8 observations and the number of features I have is 1000, so my x matrix 
is 8 by 1000 and when I run the following, I get this error, I am not sure what 
is causing this problem. 
Error in predmat[which, , seq(nlami)] = preds :   number of items to replace is 
not a multiple of replacement length
Can it be because the number of observations is small?
Thanks a lot,Andra
[[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] help with loops

2011-08-11 Thread Srinivas Iyyer
Thank you. that was very easy. 
-srini

--- On Thu, 8/11/11, R. Michael Weylandt  wrote:

From: R. Michael Weylandt 
Subject: Re: [R] help with loops
To: "Srinivas Iyyer" 
Cc: r-help@r-project.org
Date: Thursday, August 11, 2011, 12:49 PM

unlist()

Michael Weylandt

On Thu, Aug 11, 2011 at 12:46 PM, Srinivas Iyyer  
wrote:


hi I need help with list object.



I have a list object



> a <- c('apple','orange','grape')

> b <- c('car','truck','jeep')

> c <- list(a,b)

> names(c) <- c('fruit','vehicle')

> c

$fruit

[1] "apple"  "orange" "grape"



$vehicle

[1] "car"   "truck" "jeep"





I want to write all the elements of this list in one object 'z'.



>z

[1] "apple"  "orange" "grape" "car"   "truck" "jeep"



How can I write the elements of c to z

I tried using a for loop. Could any one help me please. thanks





> z <- ''

> for (i in 1:length(c)){

+ k <- c[[i]]

+ z <- c(z,k)

+ return(z)}

Error: no function to return from, jumping to top level

>





Thank you.

srini



__

R-help@r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/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] model formula

2011-08-11 Thread Uwe Ligges



On 11.08.2011 18:32, Eik Vettorazzi wrote:

Hi Stephen,
have a look at ?update.formula

glm.turn.3<-update(glm.turn.2,.~.-termfac1:rate)



No, "1" is a level of the variable "termfac" here.

Uwe Ligges



should do the trick.
hth.

Am 11.08.2011 17:27, schrieb Bond, Stephen:

Hello useRs,

Pls help with removing a single interaction term from a formula:

summary(
 glm.turn.2<- 
glm(cbind(turn.cnt,tot.cnt-turn.cnt)~sn+poly(relAge,2,raw=T)+termfac+rate:termfac,data=fix,
   family="quasibinomial")
 )

Gives

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept)   -7.028467   0.106002 -66.305<  2e-16 ***
snFeb  0.156963   0.023660   6.634 3.27e-11 ***
snMar  0.317540   0.022883  13.876<  2e-16 ***
snApr  0.526084   0.022004  23.908<  2e-16 ***
snMay  1.026710   0.020347  50.460<  2e-16 ***
snJun  0.841044   0.021318  39.452<  2e-16 ***
snJul  0.668790   0.022530  29.685<  2e-16 ***
snAug  0.544267   0.022580  24.104<  2e-16 ***
snSep  0.389667   0.023363  16.679<  2e-16 ***
snOct  0.351294   0.023586  14.894<  2e-16 ***
snNov  0.391464   0.024057  16.272<  2e-16 ***
snDec -0.373369   0.028755 -12.985<  2e-16 ***
poly(relAge, 2, raw = T)1  2.952887   0.067455  43.776<  2e-16 ***
poly(relAge, 2, raw = T)2 -1.783907   0.064074 -27.841<  2e-16 ***
termfac2  -0.681719   0.128571  -5.302 1.14e-07 ***
termfac3  -1.032416   0.146396  -7.052 1.77e-12 ***
termfac4  -1.267011   0.108940 -11.630<  2e-16 ***
termfac5  -1.009922   0.213129  -4.739 2.15e-06 ***
termfac6   3.300301   0.203465  16.221<  2e-16 ***
termfac1:rate  0.012274   0.019895   0.6170.537
termfac2:rate  0.121724   0.013472   9.036<  2e-16 ***
termfac3:rate  0.175232   0.018987   9.229<  2e-16 ***
termfac4:rate  0.197726   0.005787  34.164<  2e-16 ***
termfac5:rate  0.145622   0.027295   5.335 9.56e-08 ***
termfac6:rate -0.362379   0.025261 -14.345<  2e-16 ***

and I would like to remove the termfac1:rate interaction. Is there a way to do 
that?
Thank you

Stephen Bond


[[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] UNC windows path beginning with backslashes: normalizePath bug??

2011-08-11 Thread Uwe Ligges
This is extremely tricky since Windows does not always accept "//" 
rather than "\\". Additionally, there is not implemented system call in 
Windows, hence ?Sys.glob tells us a "partial emulation" is provided and 
"An attempt is made to handle UNC paths starting with a double backslash."


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


Best,
Uwe Ligges


On 11.08.2011 18:29, Keith Jewell wrote:

Hi,

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

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

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

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

normalizePath("//campden/shares/workgroup/stats/R/library", winslash="/")

[1] "campden/shares/workgroup/Stats/R/library"

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

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

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

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

Any comments? Suggestions?

Best regards, and thanks in advance/

Keith Jewell

"Keith Jewell"  wrote in message news:...

Hi,

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

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

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

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

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

This was discussed in a 2009 R-devel thread starting here
, but the
patch proposed in that thread seems not to have been implemented (??).

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

Re: [R] Sweave: pdf-graphics got three times lager with R 2.13.1

2011-08-11 Thread Prof Brian Ripley

1) Read about the changes to the colourspace in 2.13.0.

2) Try R-devel: it has compression for PDF files (or use a compressor 
on your final pdf file, e.g. tools::compactPDF).


On Thu, 11 Aug 2011, Uwe Ligges wrote:




On 04.08.2011 13:44, eriksengewald wrote:

Dear R-Users,

I am using R for years now but recently I encounter a problem with the
pdf-size of graphics generated with sweave. However, I am new in this 
forum.

Hence, please don't hesitate if I am wrong here.

I use a script which runs perfectly in R 2.11.1 and the pdf-size of the
graphs is about 3 KB. Running the same script with R 2.13.1 the file size
increases to 12 KB. I am using about 300 pdf-pictures in my tex-file,
generated by sweave. So this change in file size is dramatic for the 
finally

pdf-file.

Has somebody an explanation for this phenomenon?



Sometimes improvements to the device functions may lead to such a phenomenon. 
In this case maybe since the plots are actually really small, some overhead 
matters.


A minimal reproducible example would help that someone looks into the 
details, but I doubt this is too important here. I also doubt this is Sweave 
related. Have you tried a minimal example with the pdf() device directly? 
Have you read the NEWs about changes since R-2.11.1?


Best,
Uwe Ligges





Thanks a lot for your help.

Erik

Here some more facts:
- I am running a windows system (same problem with linux system)
- This is an example of my code chunk:
<>=
PlotFunctionRef2(daten,daten_ref1,daten_ref2,g=1) //plotting function
@


--
View this message in context: 
http://r.789695.n4.nabble.com/Sweave-pdf-graphics-got-three-times-lager-with-R-2-13-1-tp3718378p3718378.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.



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

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


Re: [R] help with loops

2011-08-11 Thread R. Michael Weylandt
unlist()

Michael Weylandt

On Thu, Aug 11, 2011 at 12:46 PM, Srinivas Iyyer
wrote:

> hi I need help with list object.
>
> I have a list object
>
> > a <- c('apple','orange','grape')
> > b <- c('car','truck','jeep')
> > c <- list(a,b)
> > names(c) <- c('fruit','vehicle')
> > c
> $fruit
> [1] "apple"  "orange" "grape"
>
> $vehicle
> [1] "car"   "truck" "jeep"
>
>
> I want to write all the elements of this list in one object 'z'.
>
> >z
> [1] "apple"  "orange" "grape" "car"   "truck" "jeep"
>
> How can I write the elements of c to z
> I tried using a for loop. Could any one help me please. thanks
>
>
> > z <- ''
> > for (i in 1:length(c)){
> + k <- c[[i]]
> + z <- c(z,k)
> + return(z)}
> Error: no function to return from, jumping to top level
> >
>
>
> Thank you.
> srini
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] help with loops

2011-08-11 Thread Srinivas Iyyer
hi I need help with list object. 

I have a list object

> a <- c('apple','orange','grape')
> b <- c('car','truck','jeep')
> c <- list(a,b)
> names(c) <- c('fruit','vehicle')
> c
$fruit
[1] "apple"  "orange" "grape" 

$vehicle
[1] "car"   "truck" "jeep" 


I want to write all the elements of this list in one object 'z'. 

>z
[1] "apple"  "orange" "grape" "car"   "truck" "jeep"

How can I write the elements of c to z
I tried using a for loop. Could any one help me please. thanks


> z <- ''
> for (i in 1:length(c)){
+ k <- c[[i]]
+ z <- c(z,k)
+ return(z)} 
Error: no function to return from, jumping to top level
> 


Thank you. 
srini

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] UNC windows path beginning with backslashes: normalizePath bug??

2011-08-11 Thread Keith Jewell
Hi,

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

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

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

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

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

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

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

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

Any comments? Suggestions?

Best regards, and thanks in advance/

Keith Jewell

"Keith Jewell"  wrote in message news:...
> Hi,
>
> Back in 2010 I had a problem with 'update.packages()', which I worked 
> around by mapping a drive letter to a UNC path [described in 
>  but my 
> current workaround is
> assign(".lib.loc", sub("Server02/stats", "L:", .libPaths(), 
> ignore.case = TRUE), env=environment(.libPaths))].
>
> More recently a colleague had problems using the 'FactoMineR' plug in for 
> the Rcmdr package;
> a) directly loading 'RcmdrPlugin.FactoMineR' opened and "crashed" R 
> Commander;
> b) opening R Commander without FactoMiner, the Tools option 'Load Rcmdr 
> plug-in(s)...' was greyed out.
>
> It transpired that in .libPaths() the path to the library holding 
> 'RcmdrPlugin.FactoMineR' was specified as a UNC address: 
> Server02/stats/R/library/2.13>. Mapping a virtual drive letter (e.g. 
> L:) and specifying the path in .libPaths() as a 'local file system' (LFS) 
> address  fixed the problem.
>
> I contacted Professor Fox (maintainer of Rcmdr) who told me that Rcmdr 
> finds plug-in packages via the command
>  plugins <- unlist(lapply(.libPaths(), function(x) Sys.glob(file.path(x, 
> "*/etc/menus.txt"
> Because file.path and Sys.glob are both vectorised I think (but am not 
> certain) that this could be simplified to:
>  plugins <- Sys.glob(file.path(.libPaths(), "*/etc/menus.txt"))
> but that's by the way, the problem seems to lie in Sys.glob under Windows 
> operating systems.
>
> I note that 'help(Sys.glob)' on my Windows system  differs from 
> .
> The latter says "For precise details, see your system's documentation on 
> the glob system call.  There is a POSIX 1003.2 standard   The rest 
> of these details are indicative (and based on the POSIX standard)".
> On Windows "The glob system call is not part of Windows, and we supply a 
> partial emulation.  An attempt is made to handle UNC paths starting 
> with a double backslash" which doesn't really inspire confidence.
>
> This was discussed in a 2009 R-devel thread starting here 
> , but the 
> patch proposed in that thread seems not to have been implemented (??).
>
> Trying to avoid Sys.glob in the Rcmdr application I came up with this:
>  list.files(path=file.path(list.files(path=.libPaths(), 
> full.names=TRUE), "etc"), pattern="^menus\\.txt$", full.names=TRUE)
> It seems to give identical results to Sys.glob for mapped drives, works 
> with UNC paths in Windows, and seems quite fast.
>
> So my questions relate to diagnosis, prognosis, and prescription (cure?).
>
> 1) Diagnosis: Am I correct that my problem(s) originate in the "partial 
> emulation" of glob in Windows.
>
> 2) Prognosis: If so, is there any likelihood that the emulation will 
> improve in the near future?
>
> 3) Prescription: If not:
>
> a) is assign(".lib.loc", sub("Server02/stats", "L:", .libPaths(), 
> ignore.c

Re: [R] model formula

2011-08-11 Thread Eik Vettorazzi
Hi Stephen,
have a look at ?update.formula

glm.turn.3<-update(glm.turn.2,.~.-termfac1:rate)

should do the trick.
hth.

Am 11.08.2011 17:27, schrieb Bond, Stephen:
> Hello useRs,
> 
> Pls help with removing a single interaction term from a formula:
> 
> summary(
> glm.turn.2 <- 
> glm(cbind(turn.cnt,tot.cnt-turn.cnt)~sn+poly(relAge,2,raw=T)+termfac+rate:termfac,data=fix,
>   family="quasibinomial")
> )
> 
> Gives
> 
> Coefficients:
>Estimate Std. Error t value Pr(>|t|)
> (Intercept)   -7.028467   0.106002 -66.305  < 2e-16 ***
> snFeb  0.156963   0.023660   6.634 3.27e-11 ***
> snMar  0.317540   0.022883  13.876  < 2e-16 ***
> snApr  0.526084   0.022004  23.908  < 2e-16 ***
> snMay  1.026710   0.020347  50.460  < 2e-16 ***
> snJun  0.841044   0.021318  39.452  < 2e-16 ***
> snJul  0.668790   0.022530  29.685  < 2e-16 ***
> snAug  0.544267   0.022580  24.104  < 2e-16 ***
> snSep  0.389667   0.023363  16.679  < 2e-16 ***
> snOct  0.351294   0.023586  14.894  < 2e-16 ***
> snNov  0.391464   0.024057  16.272  < 2e-16 ***
> snDec -0.373369   0.028755 -12.985  < 2e-16 ***
> poly(relAge, 2, raw = T)1  2.952887   0.067455  43.776  < 2e-16 ***
> poly(relAge, 2, raw = T)2 -1.783907   0.064074 -27.841  < 2e-16 ***
> termfac2  -0.681719   0.128571  -5.302 1.14e-07 ***
> termfac3  -1.032416   0.146396  -7.052 1.77e-12 ***
> termfac4  -1.267011   0.108940 -11.630  < 2e-16 ***
> termfac5  -1.009922   0.213129  -4.739 2.15e-06 ***
> termfac6   3.300301   0.203465  16.221  < 2e-16 ***
> termfac1:rate  0.012274   0.019895   0.6170.537
> termfac2:rate  0.121724   0.013472   9.036  < 2e-16 ***
> termfac3:rate  0.175232   0.018987   9.229  < 2e-16 ***
> termfac4:rate  0.197726   0.005787  34.164  < 2e-16 ***
> termfac5:rate  0.145622   0.027295   5.335 9.56e-08 ***
> termfac6:rate -0.362379   0.025261 -14.345  < 2e-16 ***
> 
> and I would like to remove the termfac1:rate interaction. Is there a way to 
> do that?
> Thank you
> 
> Stephen Bond
> 
> 
>   [[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.

-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

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


Re: [R] improve formatting of HTML table

2011-08-11 Thread Barry Rowlingson
On Thu, Aug 11, 2011 at 5:04 PM, Juliet Hannah  wrote:
> I am trying to improve the look of an HTML table for a report (that
> needs to be pasted into Word).

> In the output, I would like to improve the justification of the
> numbers (or any other suggestion to make
> the HTML look nicer). The columns are a little hard to read.

 Its not really the HTML's job to look nice, HTML is (supposed to be)
purely semantic. Here is a table, here is a row, here is a cell with
some stuff in it.

 To make a web page look nice you write an accompanying CSS file that
styles the HTML - blue background, purple text and so on. But you want
to paste into Word.

 I pasted it into OpenOffice (not got Word) and could easily style it
from there - highlight the column, set left-justification and so on.
Word should be similar. If you love Word for its wysiwyg behaviour, I
suggest you do that.

Barry

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


Re: [R] model formula

2011-08-11 Thread Bond, Stephen
Using glm.fit

I can remove the unwanted column from model.matrix(glm.turn.2) manually and 
then call glm.fit directly.

Q: how can I stuff the output from glm.fit into a regular glm object, so I can 
use prediction functions, etc.?? the help does not describe how to use output 
from glm.fit in the way a glm model can be used.

Thanks everybody.

Stephen 

-Original Message-
From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] 
Sent: Thursday, August 11, 2011 11:40 AM
To: Bond, Stephen
Cc: r-help@r-project.org
Subject: Re: [R] model formula



On 11.08.2011 17:27, Bond, Stephen wrote:
> Hello useRs,
>
> Pls help with removing a single interaction term from a formula:
>
> summary(
>  glm.turn.2<- 
> glm(cbind(turn.cnt,tot.cnt-turn.cnt)~sn+poly(relAge,2,raw=T)+termfac+rate:termfac,data=fix,
>family="quasibinomial")
>  )
>
> Gives
>
> Coefficients:
> Estimate Std. Error t value Pr(>|t|)
> (Intercept)   -7.028467   0.106002 -66.305<  2e-16 ***
> snFeb  0.156963   0.023660   6.634 3.27e-11 ***
> snMar  0.317540   0.022883  13.876<  2e-16 ***
> snApr  0.526084   0.022004  23.908<  2e-16 ***
> snMay  1.026710   0.020347  50.460<  2e-16 ***
> snJun  0.841044   0.021318  39.452<  2e-16 ***
> snJul  0.668790   0.022530  29.685<  2e-16 ***
> snAug  0.544267   0.022580  24.104<  2e-16 ***
> snSep  0.389667   0.023363  16.679<  2e-16 ***
> snOct  0.351294   0.023586  14.894<  2e-16 ***
> snNov  0.391464   0.024057  16.272<  2e-16 ***
> snDec -0.373369   0.028755 -12.985<  2e-16 ***
> poly(relAge, 2, raw = T)1  2.952887   0.067455  43.776<  2e-16 ***
> poly(relAge, 2, raw = T)2 -1.783907   0.064074 -27.841<  2e-16 ***
> termfac2  -0.681719   0.128571  -5.302 1.14e-07 ***
> termfac3  -1.032416   0.146396  -7.052 1.77e-12 ***
> termfac4  -1.267011   0.108940 -11.630<  2e-16 ***
> termfac5  -1.009922   0.213129  -4.739 2.15e-06 ***
> termfac6   3.300301   0.203465  16.221<  2e-16 ***
> termfac1:rate  0.012274   0.019895   0.6170.537
> termfac2:rate  0.121724   0.013472   9.036<  2e-16 ***
> termfac3:rate  0.175232   0.018987   9.229<  2e-16 ***
> termfac4:rate  0.197726   0.005787  34.164<  2e-16 ***
> termfac5:rate  0.145622   0.027295   5.335 9.56e-08 ***
> termfac6:rate -0.362379   0.025261 -14.345<  2e-16 ***
>
> and I would like to remove the termfac1:rate interaction. Is there a way to 
> do that?
> Thank you

And what do you want to do with the observations with termfac=1 then? 
Ignore? Also move to the Intercept?

Uwe Ligges



>
> Stephen Bond
>
>
>   [[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] Sweave: pdf-graphics got three times lager with R 2.13.1

2011-08-11 Thread Uwe Ligges



On 04.08.2011 13:44, eriksengewald wrote:

Dear R-Users,

I am using R for years now but recently I encounter a problem with the
pdf-size of graphics generated with sweave. However, I am new in this forum.
Hence, please don't hesitate if I am wrong here.

I use a script which runs perfectly in R 2.11.1 and the pdf-size of the
graphs is about 3 KB. Running the same script with R 2.13.1 the file size
increases to 12 KB. I am using about 300 pdf-pictures in my tex-file,
generated by sweave. So this change in file size is dramatic for the finally
pdf-file.

Has somebody an explanation for this phenomenon?



Sometimes improvements to the device functions may lead to such a 
phenomenon. In this case maybe since the plots are actually really 
small, some overhead matters.


A minimal reproducible example would help that someone looks into the 
details, but I doubt this is too important here. I also doubt this is 
Sweave related. Have you tried a minimal example with the pdf() device 
directly? Have you read the NEWs about changes since R-2.11.1?


Best,
Uwe Ligges





Thanks a lot for your help.

Erik

Here some more facts:
- I am running a windows system (same problem with linux system)
- This is an example of my code chunk:
<>=
PlotFunctionRef2(daten,daten_ref1,daten_ref2,g=1) //plotting function
@


--
View this message in context: 
http://r.789695.n4.nabble.com/Sweave-pdf-graphics-got-three-times-lager-with-R-2-13-1-tp3718378p3718378.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] Can R handle a matrix with 8 billion entries?

2011-08-11 Thread Łukasz Ręcławowicz
2011/8/11 Chris Howden 

> In that my distance matrix has too many entries for R's architecture to
> know how to store in
>  memory
>

There was an multiv package with hierclust function and a bign option.
"Is n big? If storage is problemsome, a different implementation of the Ward
criterion may be tried. This determines dissimilarities on the fly, and
hence requires O(n) storage."
But it's orphaned now and makeconf has troubles with making dll.



-- 
Mi³ego dnia

[[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] improve formatting of HTML table

2011-08-11 Thread Uwe Ligges

Please report to the package maintainer.

Uwe Ligges

On 11.08.2011 18:04, Juliet Hannah wrote:

I am trying to improve the look of an HTML table for a report (that
needs to be pasted into Word).

Here is an example.

table2<- structure(c(26L, 0L, 40L, 0L, 10L, 0L, 0L, 188L, 0L, 281L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 4L), .Dim = c(6L, 3L), .Dimnames = structure(list(
 myvar = c("Don't know", "Somewhat likely", "Somewhat unlikely",
 "Very likely", "Very unlikely", NA), var_recode = c("0", "1",
 NA)), .Names = c("myvar", "var_recode")), class = "table")


library("R2HTML")
.HTML.file = paste(getwd(), "/example.html", sep = "")
HTML(table2)


In the output, I would like to improve the justification of the
numbers (or any other suggestion to make
the HTML look nicer). The columns are a little hard to read.

Thanks.


sessionInfo()

R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
States.1252LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

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

other attached packages:
[1] R2HTML_2.2

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

2011-08-11 Thread Juliet Hannah
I am trying to improve the look of an HTML table for a report (that
needs to be pasted into Word).

Here is an example.

table2 <- structure(c(26L, 0L, 40L, 0L, 10L, 0L, 0L, 188L, 0L, 281L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 4L), .Dim = c(6L, 3L), .Dimnames = structure(list(
myvar = c("Don't know", "Somewhat likely", "Somewhat unlikely",
"Very likely", "Very unlikely", NA), var_recode = c("0", "1",
NA)), .Names = c("myvar", "var_recode")), class = "table")


library("R2HTML")
.HTML.file = paste(getwd(), "/example.html", sep = "")
HTML(table2)


In the output, I would like to improve the justification of the
numbers (or any other suggestion to make
the HTML look nicer). The columns are a little hard to read.

Thanks.

> sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
States.1252LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

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

other attached packages:
[1] R2HTML_2.2

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


Re: [R] generate two sets of random numbers that are correlated

2011-08-11 Thread Ista Zahn
If you want random numbers sampled from the normal distribution, you
can use the mvrnorm function in MASS.

Best,
Ista

On Thu, Aug 11, 2011 at 8:23 AM, Kathie  wrote:
> Dear R users
>
> I'd like to generate two sets of random numbers with a fixed correlation
> coefficient, say .4, using R.
>
> Any suggestion will be greatly appreciated.
>
> Regards,
>
> Kathryn Lord
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/generate-two-sets-of-random-numbers-that-are-correlated-tp3735695p3735695.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.
>



-- 
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] Extract values from a data frame

2011-08-11 Thread Ista Zahn
Hi Laura,

On Thu, Aug 11, 2011 at 7:01 AM, Lali  wrote:
> Hi everyone,
> I have a data frame that looks *sort of* like this:
>
> name <- letters[1:5]
> signal.1 <- c("12", "bad signal", "noise", "10", "X")
> length.signal.1 <- 5:9
> intensity.signal.1 <- 3:7
> signal.2 <- c("13", "noise", "19.2", "X", "V")
> length.signal.2 <- 2:6
> intensity.signal.2 <- 1:5
> signal.3 <- c("NA", "15.4", "error", "NA", "17")
> length.signal.3 <- c("NA", 2, 3, "NA", 4)
> intensity.signal.3 <- c("NA",4, 5, "NA", 5)
>
> #(there are actually up to 16 signals and 50 names, but I made this short
> for the example)
>
> df <- data.frame(cbind(name, signal.1, length.signal.1, intensity.signal.1,
> signal.2,
>                       length.signal.2, intensity.signal.2, signal.3,
> length.signal.3,
>                       intensity.signal.3))
>
>
>
> I need to "fish out" some values and have them in a new data frame.
>
> I am only interested in values in columns 2, 5 and 8 (actually seq(2, 50, 3)
> in my real df)
> I want the values that are not:
> "bad signal"
> "noise"
> "error"
> "NA"
> "V"
>
> This is the output I want (the name column is unimportant for my purposes,
> its just there as a reference for the example).
>
> (name)  S1       S2
> A        12        13
> B        15.4     (another value found in the other signals >3 not shown on
> example)
> C        19.2     (another value found in the other signals >3 not shown on
> example)
> D        10        X
> E        X         17
>
> I do know that there will always be 2 values exactly that do not match the
> exclusions named above, or none at all
>
> I have tried different approaches, grep, matching,%nin%... But as I am not
> an advanced used, I am very likely doing something wrong, because I either
> get a vector, or I get a matrix with TRUE FALSE, and usually I get the whole
> rows, and I don't want that :(
> I have also being searching the list for answers without avail.
> Any suggestions? Examples including syntax are appreciated (syntax is a
> major weak point for me).

Here is a solution using the reshape and plyr packages

library(reshape)
dfm <- melt(df[c(1, 2, 5, 8)], id = 1)
dfm.r <- dfm[!dfm$value %in% c("bad signal", "noise", "error", "NA", "V"), ]
dfm.r <- ddply(dfm.r, .(name), transform, index = paste("S",
1:length(name), sep = ""))
cast(dfm.r, name ~ index)

Best,
Ista
>
>
> Laura
>
>        [[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.
>



-- 
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] Splitting data

2011-08-11 Thread R. Michael Weylandt
This sounds very much like a recursive problem: something like this seems to
get the gist of what you want.

DataSplits <- function(Data, alpha = 0.05) {
DataSplitsCore <- function(Data, alpha, level) {
tt <- t.test(Data[,1],Data[,2])
print(tt)
if (tt$p.value > alpha) {
print(paste("Stopped at level", level))
return(invisible(TRUE))
} else {
nr = floor(NROW(Data)/2)
if (nr == 1) {print(paste("Reached Samples of Size 1")); stop}
d1 = DataSplitsCore(Data[(1:nr),], alpha = alpha, level = level
+ 1)
if (d1) return(invisible(TRUE))
d2 = DataSplitsCore(Data[-(1:nr),], alpha = alpha, level = level
+1)
if (d2) return(invisible(TRUE))
return(invisible(FALSE))
}
}
DataSplitsCore(Data, alpha = alpha, level = 1)
}

Your description wasn't the clearest about what to do when the data sizes
didn't match, but this should give you a start. Let me know if this doesn't
do as desired and I can help tweak it.

Hope this can be of help,

Michael Weylandt

PS -- You might as well use R's built in t.test function.

On Thu, Aug 11, 2011 at 5:17 AM, Marina de Wolff
wrote:

>
> I want to implement the following algorithm in R:
>
> I want to split my data, use a t test to compare both means of the groups
> to see if they significantly differ from each other. If this is a yes (p <
> alpha) I want to split again (into 4 groups) and do the same procedure
> twice,  and stop otherwise (here the problem arises). As a final result I
> would have different groups of data.
>
> I made some code where the data is splitted, until no splitting is
> possible. So for 16 datapoints, we can split 4 times with a final result of
> 16 groups (p is NA for the 4th split since sd cannot be calculated..).
>
> The code calculated all p values, but I don't want this. I want it to stop
> when p > alpha. I tried while, but didn't succeed.
>
> I hope someone can help me to acchieve my goal.
>
> This is what I tried so far with test data:
>
> a = rnorm(9,0,0.1)
> b = rnorm(7,1,0.1)
> data = c(a,b)
> plot(data)
>
> # Want to calculate max of groups/split for the data
> d = seq(1,100,1)
> n = 2^d
> m <- which(n <=length(data))
> n = n[m[1]:m[length(m)]]
>
> # All groups
> i=0
> j=0
> dx = 0
> dy =
> for (i in 1:length(n)){
> split <- length(data)/(n[i])
> for (j in 1:(n[i]/2)){
> x = data[(1 + (j-1)*(2*split)):(round(split) + (j-1)*(2*split))]
> dx = cbind(dx,x)
> y = data[((round(split)+1) + (j-1)*(2*split)):(2*j*split)]
> dy = cbind(dy,y)
> }}
>
> dx = dx[,2:dim(dx)[2]]
> dy = dy[,2:dim(dy)[2]]
>
> k=0
> meanx=0
> meany=0
> sdx=0
> sdy=0
> nx=0
> ny=0
> for (k in 1:dim(dx)[2]) {
> meanx[k] = mean(unique(dx[,k]))
> meany[k] = mean(unique(dy[,k]))
> sdx[k] = sd(unique(dx[,k]))
> sdy[k] = sd(unique(dy[,k]))
> nx[k] = length(unique(dx[,k]))
> ny[k] = length(unique(dy[,k]))
> }
>
> t = (meanx-meany)/sqrt((sdx^2/nx) + (sdy^2/ny))
> df = ((sdx^2/nx) + (sdy^2/ny))^2/((sdx^2/nx)^2/(nx-1) +
> (sdy^2/ny)^2/(ny-1))
> p = 2*pt(-abs(t),df=df)
> alpha = 0.05
>[[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] value.labels

2011-08-11 Thread Uwe Ligges



On 11.08.2011 16:10, zcatav wrote:

Hello R people,

I have a "data.frame". Status variable has 3 values. 0->alive, 1->dead and
2->missed
Status as a factor have correct levels. Levels and labels output as follows;

levels(Adbf$status); labels(Adbf$status)
[1] "0" "1" "2"
   [1] "1"   "2"   "3"   "4"   "5"   "6"   "7"   "8"   "9"   "10"
  [11] "11"  "12"  "13"  "14"  "15"  "16"  "17"  "18"  "19"  "20"
  [21] "21"  "22"  "23"  "24"  "25"  "26"  "27"  "28"  "29"  "30"
  [31] "31"  "32"  "33"  "34"  "35"  "36"  "37"  "38"  "39"  "40"
  [41] "41"  "42"  "43"  "44"  "45"  "46"  "47"  "48"  "49"  "50"

"644"

Can i add value.labels to status variable? If yes how? Can i see these
value.labels on results or graphics?



levels(Adbf$status) <- c("alive", "dead", "missed")

Uwe Ligges



Thanks.

--
View this message in context: 
http://r.789695.n4.nabble.com/value-labels-tp3735947p3735947.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] model formula

2011-08-11 Thread Uwe Ligges



On 11.08.2011 17:27, Bond, Stephen wrote:

Hello useRs,

Pls help with removing a single interaction term from a formula:

summary(
 glm.turn.2<- 
glm(cbind(turn.cnt,tot.cnt-turn.cnt)~sn+poly(relAge,2,raw=T)+termfac+rate:termfac,data=fix,
   family="quasibinomial")
 )

Gives

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept)   -7.028467   0.106002 -66.305<  2e-16 ***
snFeb  0.156963   0.023660   6.634 3.27e-11 ***
snMar  0.317540   0.022883  13.876<  2e-16 ***
snApr  0.526084   0.022004  23.908<  2e-16 ***
snMay  1.026710   0.020347  50.460<  2e-16 ***
snJun  0.841044   0.021318  39.452<  2e-16 ***
snJul  0.668790   0.022530  29.685<  2e-16 ***
snAug  0.544267   0.022580  24.104<  2e-16 ***
snSep  0.389667   0.023363  16.679<  2e-16 ***
snOct  0.351294   0.023586  14.894<  2e-16 ***
snNov  0.391464   0.024057  16.272<  2e-16 ***
snDec -0.373369   0.028755 -12.985<  2e-16 ***
poly(relAge, 2, raw = T)1  2.952887   0.067455  43.776<  2e-16 ***
poly(relAge, 2, raw = T)2 -1.783907   0.064074 -27.841<  2e-16 ***
termfac2  -0.681719   0.128571  -5.302 1.14e-07 ***
termfac3  -1.032416   0.146396  -7.052 1.77e-12 ***
termfac4  -1.267011   0.108940 -11.630<  2e-16 ***
termfac5  -1.009922   0.213129  -4.739 2.15e-06 ***
termfac6   3.300301   0.203465  16.221<  2e-16 ***
termfac1:rate  0.012274   0.019895   0.6170.537
termfac2:rate  0.121724   0.013472   9.036<  2e-16 ***
termfac3:rate  0.175232   0.018987   9.229<  2e-16 ***
termfac4:rate  0.197726   0.005787  34.164<  2e-16 ***
termfac5:rate  0.145622   0.027295   5.335 9.56e-08 ***
termfac6:rate -0.362379   0.025261 -14.345<  2e-16 ***

and I would like to remove the termfac1:rate interaction. Is there a way to do 
that?
Thank you


And what do you want to do with the observations with termfac=1 then? 
Ignore? Also move to the Intercept?


Uwe Ligges





Stephen Bond


[[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] model formula

2011-08-11 Thread Bond, Stephen
Hello useRs,

Pls help with removing a single interaction term from a formula:

summary(
glm.turn.2 <- 
glm(cbind(turn.cnt,tot.cnt-turn.cnt)~sn+poly(relAge,2,raw=T)+termfac+rate:termfac,data=fix,
  family="quasibinomial")
)

Gives

Coefficients:
   Estimate Std. Error t value Pr(>|t|)
(Intercept)   -7.028467   0.106002 -66.305  < 2e-16 ***
snFeb  0.156963   0.023660   6.634 3.27e-11 ***
snMar  0.317540   0.022883  13.876  < 2e-16 ***
snApr  0.526084   0.022004  23.908  < 2e-16 ***
snMay  1.026710   0.020347  50.460  < 2e-16 ***
snJun  0.841044   0.021318  39.452  < 2e-16 ***
snJul  0.668790   0.022530  29.685  < 2e-16 ***
snAug  0.544267   0.022580  24.104  < 2e-16 ***
snSep  0.389667   0.023363  16.679  < 2e-16 ***
snOct  0.351294   0.023586  14.894  < 2e-16 ***
snNov  0.391464   0.024057  16.272  < 2e-16 ***
snDec -0.373369   0.028755 -12.985  < 2e-16 ***
poly(relAge, 2, raw = T)1  2.952887   0.067455  43.776  < 2e-16 ***
poly(relAge, 2, raw = T)2 -1.783907   0.064074 -27.841  < 2e-16 ***
termfac2  -0.681719   0.128571  -5.302 1.14e-07 ***
termfac3  -1.032416   0.146396  -7.052 1.77e-12 ***
termfac4  -1.267011   0.108940 -11.630  < 2e-16 ***
termfac5  -1.009922   0.213129  -4.739 2.15e-06 ***
termfac6   3.300301   0.203465  16.221  < 2e-16 ***
termfac1:rate  0.012274   0.019895   0.6170.537
termfac2:rate  0.121724   0.013472   9.036  < 2e-16 ***
termfac3:rate  0.175232   0.018987   9.229  < 2e-16 ***
termfac4:rate  0.197726   0.005787  34.164  < 2e-16 ***
termfac5:rate  0.145622   0.027295   5.335 9.56e-08 ***
termfac6:rate -0.362379   0.025261 -14.345  < 2e-16 ***

and I would like to remove the termfac1:rate interaction. Is there a way to do 
that?
Thank you

Stephen Bond


[[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] value.labels

2011-08-11 Thread zcatav
Hello R people,

I have a "data.frame". Status variable has 3 values. 0->alive, 1->dead and
2->missed
Status as a factor have correct levels. Levels and labels output as follows;

levels(Adbf$status); labels(Adbf$status)
[1] "0" "1" "2"
  [1] "1"   "2"   "3"   "4"   "5"   "6"   "7"   "8"   "9"   "10" 
 [11] "11"  "12"  "13"  "14"  "15"  "16"  "17"  "18"  "19"  "20" 
 [21] "21"  "22"  "23"  "24"  "25"  "26"  "27"  "28"  "29"  "30" 
 [31] "31"  "32"  "33"  "34"  "35"  "36"  "37"  "38"  "39"  "40" 
 [41] "41"  "42"  "43"  "44"  "45"  "46"  "47"  "48"  "49"  "50" 

"644"

Can i add value.labels to status variable? If yes how? Can i see these
value.labels on results or graphics?

Thanks.

--
View this message in context: 
http://r.789695.n4.nabble.com/value-labels-tp3735947p3735947.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] Subsampling data

2011-08-11 Thread Stefán Hrafn Jónsson
*Dear R community*

* *

*I have two questions on data subsample manipulation. I am starting to use R
again after a long brake  and feel a bit rusty.*

* *

*I want to select a subsample of data for males and females separately*

* *



library(foreign)

Datatemp  <- read.spss("H:/Skjol/Data/HL/t1and2b.sav", use.value.labels = F)






> table(Datatemp$sex)



   12

3049 3702



> attributes(Datatemp)

…

$names

 [1] "nomiss""Bin"   "rad09" "year"
"sex"
"income""adults"

 [8] "children"  "student"   "retired"   "disabled"
"homemaker" "unemployed""employed"

[15] "occupation""residencysize" "educ"  "agemean"
"age"
"marital"



$codepage

[1] 1252



> MalesData <- Datatemp[Datatemp $sex==1]

> MalesData

named list()

> attributes(MalesData)

$names

character(0)




Females.Data <- Datatemp[Datatemp $sex==2]







*This subset extraction is not working. Is there anyone who can tell me what
I did wrong?*

* *

* *

*A different but related question is the use of the function paste or if I
need another function to do the following: *

* *

* *

*Rather than this*:



> m2 <- gee( Bin ~  agemean +  year,  id = rad09 , data = datause ,
subset=kyn== 1 ,

   family =  binomial, corstr ="exchangeable" )







*I want to do this (modified in  a loop). *





> subsampl <- "kyn== 1 "



> m2 <- gee( Bin ~  agemean +  year,  id = rad09 , data = datause ,
subset=paste(subsampl) ,

   family =  binomial, corstr ="exchangeable" )



Beginning Cgee S-function, @(#) geeformula.q 4.13 98/01/27

Error in gee(Bin ~ agemean + year, id = rad09, data = datause, subset =
paste(subsampl),  :

  rank-deficient model matrix







*I hope you can see what I want to do, but I think I may need other function
than paste()*

*
*

*I appreciate a lot any help. *

*
Stefan Hrafn*

[[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] "Denormalize" data

2011-08-11 Thread RobinLovelace
Hi Jeff, yes I can confirm that the xtabs solution does not work with the
original method.
Here's how it went:

HHum02 <- Hum02[1:30,] # select subset for demonstration purposes
> HHum02[1:5,]
 CASW Btype   Yr CO2Group NumVeh
170597 00CCFA  CARS 2002C  2
170598 00CCFA  CARS 2002D  2
170599 00CCFA  CARS 2002E 22
170600 00CCFA  CARS 2002F 32
170601 00CCFA  CARS 2002G 32

HHH <- xtabs(NumVeh~CASW+CO2Group, data = HHum02)

Result:
...
...
38UFHG  0 0  0  0  0  0  0  0  0  0  0  0 0 00
  38UFHH  0 0  0  0  0  0  0  0  0  0  0  0 0 00
 [ reached getOption("max.print") -- omitted 1303 rows ]]


As I said I thought this was due to R remembering the invisible rows that
were supposed to be removed during the HHum02 <- Hum02[1:30,] command.
However I found the only 0 outputs with the full dataset:

> head(xtabs(NumVeh~CASW+CO2Group, data = Hum02))
CO2Group
CASWA: Up to 100  B  C  D  E  F  G  H  I  J  K  K(L)  K(M) non-cars
 0 0  0  0  0  0  0  0  0  0  0  0 0 00
  00AAFA 0 0  0  0  0  0  0  0  0  0  0  0 0 00
  00AAFE 0 0  0  0  0  0  0  0  0  0  0  0 0 00
  00AAFQ 0 0  0  0  0  0  0  0  0  0  0  0 0 00
  00AAFS 0 0  0  0  0  0  0  0  0  0  0  0 0 00
  00AAFT 0 0  0  0  0  0  0  0  0  0  0  0 0 00


Interestingly, melt and cast do not suffer from this problem:

mdata <- melt(HHum02)
cast(mdata, CASW~CO2Group~variable, sum)

Result:

CASW  C  D  E  F  G  H  I  J  K  K(L)  K(M) non-cars
  00CCFA  2  2 22 32 32 12 12  9  9 8 2   66
  00CCFB  0  1 11 12 20 17  4 10  5 2 1   35

When you do the xtabs option on an edited dataset it does work:
head(HHum.alt)
 cas btypy co2 numv
1 00CCFA CARS 2002   C2
2 00CCFA CARS 2002   D2
3 00CCFA CARS 2002   E   22
4 00CCFA CARS 2002   F   32
5 00CCFA CARS 2002   G   32
6 00CCFA CARS 2002   H   12

> head(xtabs( numv ~ cas+co2, data= HHum.alt)) 
co2
cas   C  D  E  F  G  H  I  J  K  K(L)  K(M) non-cars
  00CCFA  2  2 22 32 32 12 12  9  9 8 2   66
  00CCFB  0  1 11 12 20 17  4 10  5 2 1   35


So all-in all it looks like xtabs does work, but that it gets put-off by the
superfluous column beginning 170597  in Hum02.
That raises a couple of questions:
(1) how do I remove the superfluous column (sorry for asking noobie question
- I did look, promise!)?
(2) why can melt-cast deal with this superfluous column while xtabs cannot?

My conclusion is that melt-cast is more robust. 

All data and history should be available here
http://dl.dropbox.com/u/15008199/Work-Rgeo1.zip
 if anyone wants to replicate this. Many thanks, 
Robin





 


--
View this message in context: 
http://r.789695.n4.nabble.com/Denormalize-data-tp3729817p3735488.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] generate two sets of random numbers that are correlated

2011-08-11 Thread R. Michael Weylandt
Well, without saying what sort of random numbers you mean, it's a little
hard, but here's one straightforward way to do it for 2 normally distributed
rvs.

X1 = rnorm(100)
X2 = rnorm(100)

Y = X1
Z = 0.4*X1+sqrt(1-0.4)*X2

then

cor(Y,Z) ~ 0.4

In function terms:

CorrNorm <- function(n=100, rho = 0.4) {
 X1 = rnorm(n); X2 = rnorm(n)
 Z = cbind(X1, rho*X1+sqrt(1-rho^2)*X2)
 return(Z)
}

Hope this helps,

Michael Weylandt

PS -- Depending on what you may want/need/intend check out the rmnorm()
function for a multivariate random normal.

On Thu, Aug 11, 2011 at 8:23 AM, Kathie  wrote:

> Dear R users
>
> I'd like to generate two sets of random numbers with a fixed correlation
> coefficient, say .4, using R.
>
> Any suggestion will be greatly appreciated.
>
> Regards,
>
> Kathryn Lord
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/generate-two-sets-of-random-numbers-that-are-correlated-tp3735695p3735695.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] Splitting data

2011-08-11 Thread Marina de Wolff

I want to implement the following algorithm in R:
 
I want to split my data, use a t test to compare both means of the groups to 
see if they significantly differ from each other. If this is a yes (p < alpha) 
I want to split again (into 4 groups) and do the same procedure twice,  and 
stop otherwise (here the problem arises). As a final result I would have 
different groups of data.
 
I made some code where the data is splitted, until no splitting is possible. So 
for 16 datapoints, we can split 4 times with a final result of 16 groups (p is 
NA for the 4th split since sd cannot be calculated..).
 
The code calculated all p values, but I don't want this. I want it to stop when 
p > alpha. I tried while, but didn't succeed. 
 
I hope someone can help me to acchieve my goal.
 
This is what I tried so far with test data:
 
a = rnorm(9,0,0.1) 
b = rnorm(7,1,0.1)
data = c(a,b)
plot(data)
 
# Want to calculate max of groups/split for the data
d = seq(1,100,1)
n = 2^d
m <- which(n <=length(data))
n = n[m[1]:m[length(m)]]
 
# All groups
i=0
j=0
dx = 0
dy = 
for (i in 1:length(n)){
split <- length(data)/(n[i])
for (j in 1:(n[i]/2)){
x = data[(1 + (j-1)*(2*split)):(round(split) + (j-1)*(2*split))]
dx = cbind(dx,x)
y = data[((round(split)+1) + (j-1)*(2*split)):(2*j*split)]
dy = cbind(dy,y)
}}
 
dx = dx[,2:dim(dx)[2]]
dy = dy[,2:dim(dy)[2]]
 
k=0
meanx=0
meany=0
sdx=0
sdy=0
nx=0
ny=0
for (k in 1:dim(dx)[2]) {
meanx[k] = mean(unique(dx[,k]))
meany[k] = mean(unique(dy[,k]))
sdx[k] = sd(unique(dx[,k]))
sdy[k] = sd(unique(dy[,k]))
nx[k] = length(unique(dx[,k]))
ny[k] = length(unique(dy[,k]))
}
 
t = (meanx-meany)/sqrt((sdx^2/nx) + (sdy^2/ny))
df = ((sdx^2/nx) + (sdy^2/ny))^2/((sdx^2/nx)^2/(nx-1) + (sdy^2/ny)^2/(ny-1))
p = 2*pt(-abs(t),df=df)
alpha = 0.05  
[[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] To import data to R from Excel

2011-08-11 Thread Uwe Ligges
Or just read the R Data Import/Export manual that includes comments on 
how to deal with Excel.


Best,
Uwe Ligges




On 11.08.2011 11:21, Petr PIKAL wrote:

Hi


In Excel, make sure that your data has a format that corresponds to an R



data frame (first row with column names, consistent column size and data

type).

Export your .XLS worksheet as .CSV file (mydata.csv).
In R, read it into a data frame with


read.csv( "mydata.csv" )


Another option is simple copy/paste way.

In Excel select the data area you want to transfer (preferably formatted
like stated above.
Press Ctrl-C
Change to R
In R command window write

my.data.frame<- read.delim("clipboard",...further options according to
your locale...)

Regards
Petr



> From here, you shold be able to reshapte the data in a way that you can



draw your boxplot.

Rgds,
Rainer


On Thursday 11 August 2011 11:29:23 Blessy chemmannur Francis wrote:

Sir,
   I am a beginner in R language. I want to import data from

excel to

R. My data contains not only numeric values but also string values.I

want to

draw a boxplot graph . I can't import or write this string data. it is
essential for my graph.Please give me a suggestion for This.
Thanking You,


BLESSY.C.F.

[[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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Capture R-Console Output to Excel with RExcel

2011-08-11 Thread David Winsemius


On Aug 11, 2011, at 7:46 AM, Meier Dario wrote:


Hello All

I've just started to use RExcel instead of CMD Batches. But I don't  
get

the console output to an data.frame and push to Excel.

With the CMD batch you got the console out relatively easy with

C:\LocalData\R\bin\R CMD BATCH --slave %rscript% %logfile%

to a file. But how can I get it to Excel with RExcel an VBA?


I am guessing that either sink()  or capture.output() with the  
"clipboard" as the destination file should work. It's just a character  
stream, right? Cannot test since I'm on a different OS. You will  
undoubtedly need to process further, perhaps with the "import text to  
columns" using the fixed-width format panel since console output will  
not be tab delimited.


(There is also an RExcel Mailing list, although this doesn't really  
seem like the issues involved depend on RExcel.)


--

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] R crashes when communicating with JAGS

2011-08-11 Thread Uwe Ligges

Works for me with JAGS 3.1.0.

Uwe Ligges


On 11.08.2011 14:09, David Wooff wrote:

There is a thread on this topic already:
http://finzi.psych.upenn.edu/Rhelp10/2010-August/250934.html

I'm rather mystified by a similar problem and wondering whether I've
overlooked something obvious. I'm running with latest versions of R and
all packages, and latest version of JAGS running under Windows 7.

Here's the problem. I have some source code. It's given below - standard
stuff - seeds example from BUGS volume 1. I'm using R2WinBUGS only to
create the model file, and R2jags as a front end to JAGS. I have the
same problem whether or not I use R2jags.

1. If I start RGUI and source the code from a source file. R crashes
when it tries to execute jags().

Problem Event Name: APPCRASH
Application Name: Rgui.exe
Application Version: 2.131.56322.0
Application Timestamp: 4e171fac
Fault Module Name: StackHash_486a
Fault Module Version: 6.1.7601.17514
Fault Module Timestamp: 4ce7ba58
Exception Code: c374
Exception Offset: 000ce653
OS Version: 6.1.7601.2.1.0.768.3
Locale ID: 2057
Additional Information 1: 486a
Additional Information 2: 486a33f7a181da7ba2feae88b7ee12b6
Additional Information 3: 9e02
Additional Information 4: 9e02b3fab8ac2ab41c0e936dfef5c6d4

2. If I start RGUI and cut and paste the code from a source file.
Everything works fine.

3. If, after (2) I source the code - and other examples from source
files - everything works fine.

This seems to indicate that there is some kind of initialization which
needs to happen before JAGS will work; that this initialization is
carried out when typing commands into the console, but not carried out
when sourcing identical commands from a source file.

I have tried delaying issuing the jags command when sourcing (using
readline()) in case the issue was with readiness of the bugs model being
written to file; but the crash still happens with any such delay.

I'd be most grateful for tips to circumvent this behaviour.

Cheers,

David

Here's the test code:
#---
require(R2WinBUGS)
require(rjags)
require(R2jags)
## write model file:
print(list.modules())
write.model(con="blah.bug",model=function() {
for( i in 1 : N ) {
r[i] ~ dbin(p[i],n[i])
b[i] ~ dnorm(0.0,tau)
logit(p[i]) <- alpha0 + alpha1 * x1[i] + alpha2 * x2[i] +
alpha12 * x1[i] * x2[i] + b[i]
}
alpha0 ~ dnorm(0.0,1.0E-6)
alpha1 ~ dnorm(0.0,1.0E-6)
alpha2 ~ dnorm(0.0,1.0E-6)
alpha12 ~ dnorm(0.0,1.0E-6)
tau ~ dgamma(0.001,0.001)
sigma <- 1 / sqrt(tau)
})
g<-jags(model.file='blah.bug',
data = list(r = c(10, 23, 23, 26, 17, 5, 53, 55, 32, 46, 10, 8, 10, 8,
23, 0, 3, 22, 15, 32, 3),
n = c(39, 62, 81, 51, 39, 6, 74, 72, 51, 79, 13, 16, 30, 28, 45, 4, 12,
41, 30, 51, 7),
x1 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
x2 = c(0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1),
N = 21),
parameters=c('alpha0', 'alpha1','alpha2','alpha12','tau'),
inits=list(alpha0 = 0, alpha1 = 0, alpha2 = 0, alpha12 = 0, tau = 1) ,
n.iter=1)
#---




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


[R] Extract values from a data frame

2011-08-11 Thread Lali
Hi everyone,
I have a data frame that looks *sort of* like this:

name <- letters[1:5]
signal.1 <- c("12", "bad signal", "noise", "10", "X")
length.signal.1 <- 5:9
intensity.signal.1 <- 3:7
signal.2 <- c("13", "noise", "19.2", "X", "V")
length.signal.2 <- 2:6
intensity.signal.2 <- 1:5
signal.3 <- c("NA", "15.4", "error", "NA", "17")
length.signal.3 <- c("NA", 2, 3, "NA", 4)
intensity.signal.3 <- c("NA",4, 5, "NA", 5)

#(there are actually up to 16 signals and 50 names, but I made this short
for the example)

df <- data.frame(cbind(name, signal.1, length.signal.1, intensity.signal.1,
signal.2,
   length.signal.2, intensity.signal.2, signal.3,
length.signal.3,
   intensity.signal.3))



I need to "fish out" some values and have them in a new data frame.

I am only interested in values in columns 2, 5 and 8 (actually seq(2, 50, 3)
in my real df)
I want the values that are not:
"bad signal"
"noise"
"error"
"NA"
"V"

This is the output I want (the name column is unimportant for my purposes,
its just there as a reference for the example).

(name)  S1   S2
A1213
B15.4 (another value found in the other signals >3 not shown on
example)
C19.2 (another value found in the other signals >3 not shown on
example)
D10X
EX 17

I do know that there will always be 2 values exactly that do not match the
exclusions named above, or none at all

I have tried different approaches, grep, matching,%nin%... But as I am not
an advanced used, I am very likely doing something wrong, because I either
get a vector, or I get a matrix with TRUE FALSE, and usually I get the whole
rows, and I don't want that :(
I have also being searching the list for answers without avail.
Any suggestions? Examples including syntax are appreciated (syntax is a
major weak point for me).


Laura

[[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] generate two sets of random numbers that are correlated

2011-08-11 Thread Kathie
Dear R users

I'd like to generate two sets of random numbers with a fixed correlation
coefficient, say .4, using R.

Any suggestion will be greatly appreciated.

Regards,

Kathryn Lord 

--
View this message in context: 
http://r.789695.n4.nabble.com/generate-two-sets-of-random-numbers-that-are-correlated-tp3735695p3735695.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] Capture R-Console Output to Excel with RExcel

2011-08-11 Thread Meier Dario
Hello All

I've just started to use RExcel instead of CMD Batches. But I don't get
the console output to an data.frame and push to Excel.

With the CMD batch you got the console out relatively easy with

C:\LocalData\R\bin\R CMD BATCH --slave %rscript% %logfile%

to a file. But how can I get it to Excel with RExcel an VBA?

Thanks,
Dario

[[alternative HTML version deleted]]

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


[R] R crashes when communicating with JAGS

2011-08-11 Thread David Wooff

There is a thread on this topic already:
http://finzi.psych.upenn.edu/Rhelp10/2010-August/250934.html

I'm rather mystified by a similar problem and wondering whether I've 
overlooked something obvious. I'm running with latest versions of R and 
all packages, and latest version of JAGS running under Windows 7.


Here's the problem. I have some source code. It's given below - standard 
stuff - seeds example from BUGS volume 1. I'm using R2WinBUGS only to 
create the model file, and R2jags as a front end to JAGS. I have the 
same problem whether or not I use R2jags.


1. If I start RGUI and source the code from a source file. R crashes 
when it tries to execute jags().


  Problem Event Name:   APPCRASH
  Application Name: Rgui.exe
  Application Version:  2.131.56322.0
  Application Timestamp:4e171fac
  Fault Module Name:StackHash_486a
  Fault Module Version: 6.1.7601.17514
  Fault Module Timestamp:   4ce7ba58
  Exception Code:   c374
  Exception Offset: 000ce653
  OS Version:   6.1.7601.2.1.0.768.3
  Locale ID:2057
  Additional Information 1: 486a
  Additional Information 2: 486a33f7a181da7ba2feae88b7ee12b6
  Additional Information 3: 9e02
  Additional Information 4: 9e02b3fab8ac2ab41c0e936dfef5c6d4

2. If I start RGUI and cut and paste the code from a source file. 
Everything works fine.


3. If, after (2) I source the code - and other examples from source 
files - everything works fine.


This seems to indicate that there is some kind of initialization which 
needs to happen before JAGS will work; that this initialization is 
carried out when typing commands into the console, but not carried out 
when sourcing identical commands from a source file.


I have tried delaying issuing the jags command when sourcing (using 
readline()) in case the issue was with readiness of the bugs model being 
written to file; but the crash still happens with any such delay.


I'd be most grateful for tips to circumvent this behaviour.

Cheers,

David

Here's the test code:
#---
   require(R2WinBUGS)
   require(rjags)
   require(R2jags)
   ## write model file:
   print(list.modules())
   write.model(con="blah.bug",model=function() {
  for( i in 1 : N ) {
 r[i] ~ dbin(p[i],n[i])
 b[i] ~ dnorm(0.0,tau)
 logit(p[i]) <- alpha0 + alpha1 * x1[i] + alpha2 * x2[i] +
 alpha12 * x1[i] * x2[i] + b[i]
  }
  alpha0 ~ dnorm(0.0,1.0E-6)
  alpha1 ~ dnorm(0.0,1.0E-6)
  alpha2 ~ dnorm(0.0,1.0E-6)
  alpha12 ~ dnorm(0.0,1.0E-6)
  tau ~ dgamma(0.001,0.001)
  sigma <- 1 / sqrt(tau)
   })
   g<-jags(model.file='blah.bug',
  data = list(r = c(10, 23, 23, 26, 17, 5, 53, 55, 32, 46, 
10, 8, 10, 8, 23, 0, 3, 22, 15, 32, 3),
  n = c(39, 62, 81, 51, 39, 6, 74, 72, 51, 79, 13, 16, 30, 28, 45, 
4, 12, 41, 30, 51, 7),
  x1 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1),
  x2 = c(0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 
1, 1),

  N = 21),
  parameters=c('alpha0', 'alpha1','alpha2','alpha12','tau'),
  inits=list(alpha0 = 0, alpha1 = 0, alpha2 = 0, alpha12 = 
0, tau = 1) ,

  n.iter=1)
#---


--
Dr David Wooff,
Director, Statistics and Mathematics Consultancy Unit,
& Senior Lecturer in Statistics, University of Durham.
Department of Mathematical Sciences, Science Laboratories,
South Road, Durham, DH1 3LE, UK. email: d.a.wo...@dur.ac.uk
Tel. 0191 334 3121, Fax 0191 334 3051.
Web: http://maths.dur.ac.uk/stats/people/daw/daw.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] round() a data frame containing 'character' variables?

2011-08-11 Thread David Winsemius


On Aug 10, 2011, at 5:46 AM, Liviu Andronic wrote:


Hello

On Wed, Aug 10, 2011 at 11:41 AM, Dimitris Rizopoulos
 wrote:

One approach is the following:

numVars <- sapply(iris, is.numeric)
iris[numVars] <- lapply(iris[numVars], round, digits = 2)
head(iris)


That's interesting, but still doesn't do what I need. Since it's a
read-only View() operation I would like to avoid at all cost modifying
the original data frame. And since my data frames are relatively big,
I would like to avoid generating unnecessary copies. Basically I would
need round() to ignore objects that it knows it cannot handle.


Then drop the assignment operation and just print:

( lapply(iris[numVars], round, digits = 2) )

Or set your digits argument to print:

print( head(iris), digits=1)

Or did I miss something?

--

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] round() a data frame containing 'character' variables?

2011-08-11 Thread Martin Maechler
> Liviu Andronic 
> on Wed, 10 Aug 2011 11:46:55 +0200 writes:

> Hello On Wed, Aug 10, 2011 at 11:41 AM, Dimitris
> Rizopoulos  wrote:
>> One approach is the following:
>> 
>> numVars <- sapply(iris, is.numeric) iris[numVars] <-
>> lapply(iris[numVars], round, digits = 2) head(iris)
>> 
> That's interesting, but still doesn't do what I
> need. Since it's a read-only View() operation I would like
> to avoid at all cost modifying the original data
> frame. And since my data frames are relatively big, I
> would like to avoid generating unnecessary
> copies. Basically I would need round() to ignore objects
> that it knows it cannot handle.

> Any other ideas?

Well, as you say it's  "View()" only, so why don't you just
"view" the result of

something like
  print(, digits = 2)

(it does correspond to  signif(), rather than round(),
 but I think that that's more sensible anyway).

Martin

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


[R] How to specify specific contrasts on repeated measures ANOVA using car?

2011-08-11 Thread hen...@singmann.org
Hello everyone,

I am trying to run a repeated measures Anova in R followed by some specific
contrasts on that dataset. So far I think the correct approach would be to use
Anova() from the car package.
 
Lets illustrate my question with the example taken from ?Anova using the
OBrienKaiser data:
We have a design with 2 between subjects factor, treatment (3 levels: control,
A, B) and gender (M vs. F), and 2 repeated-measures (within subjects) factors,
phase (3 levels: pretest, posttest, followup) and hour (5 levels: 1 to 5).

The standard ANOVA table is given by (in difference to example(Anova) I switched
to Type 3 Sums of Squares, that is what my field wants):

require(car)
phase <- factor(rep(c("pretest", "posttest", "followup"), c(5, 5, 5)),
levels=c("pretest", "posttest", "followup"))
hour <- ordered(rep(1:5, 3))
idata <- data.frame(phase, hour)
mod.ok <- lm(cbind(pre.1, pre.2, pre.3, pre.4, pre.5, post.1, post.2, post.3,
post.4, post.5, fup.1, fup.2, fup.3, fup.4, fup.5) ~  treatment*gender,
data=OBrienKaiser)
av.ok <- Anova(mod.ok, idata=idata, idesign=~phase*hour, type = 3)
summary(av.ok, multivariate=FALSE)

Now, imagine that the highest order interaction would have been significant
(which is not the case) and we would like to explore it further with the
following contrasts:
Is there a difference between hours 1&2 versus hours 3 (contrast 1) and between
hours 1&2 versus hours 4&5 (contrast 2) in the treamtment conditions (A&B
together)? In other words, how do I specify these contrasts: 1. ((treatment %in%
c("A", "B")) & (hour %in% 1:2)) versus ((treatment %in% c("A", "B")) & (hour
%in% 3))
2. ((treatment %in% c("A", "B")) & (hour %in% 1:2)) versus ((treatment %in%
c("A", "B")) & (hour %in% 4:5))

My idea would be to run another ANOVA ommitting the non-needed treatment
condition (control). However, I still have no idea how to set up the appropriate
within-subject contrast matrix comparing hours 1&2 with 3 and 4&5, respectively.
And I am not sure if ommitting the non-needed treatment group is indeed a good
idea as it changes the overall errorterm.

Before going for Anova() I was also thinking going for lme. However, there are
small differences in F and p values between textbook ANOVA and what is returned
from anove(lme) (see my question here:
http://stats.stackexchange.com/q/14088/442). I also tried using Anova() with lme
objects, but Anova() seems to only returns Chi² values for lme objects. So I
ended up giving all my hope in John Fox and Anova().

I hope this question on contrsats is okay. I tried to understand Venables &
Ripley on model matrices (chapter 6.2, pp. 144, 4th ed.) but this did not help
me at all.

Thanks in advance,

Henrik

--
Dipl. Psych. Henrik Singmann
PhD Student
Institute of Psychology
Albert-Ludwigs-Universität Freiburg
http://www.psychologie.uni-freiburg.de/Members/singmann
[[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] Data frame to list?

2011-08-11 Thread David Winsemius


On Aug 11, 2011, at 8:24 AM, Michael Karol wrote:


Perhaps the split() function would do.


Something like split(dfrm, 1:nrow(dfrm)) or split(dfrm, rownames(dfrm))

--  


Regards,
Michael

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org 
] On Behalf Of Jonathan Greenberg

Sent: Wednesday, August 10, 2011 10:36 PM
To: r-help
Subject: [R] Data frame to list?

R-helpers:

Is there an easy way to transfer a data frame to a list, where each
list element is a dataframe containing a single row from the original
data frame?

--j


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] Data frame to list?

2011-08-11 Thread Michael Karol
Perhaps the split() function would do.

Regards, 
Michael

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Jonathan Greenberg
Sent: Wednesday, August 10, 2011 10:36 PM
To: r-help
Subject: [R] Data frame to list?

R-helpers:

Is there an easy way to transfer a data frame to a list, where each
list element is a dataframe containing a single row from the original
data frame?

--j

-- 
Jonathan A. Greenberg, PhD
Assistant Project Scientist
Center for Spatial Technologies and Remote Sensing (CSTARS)
Department of Land, Air and Water Resources
University of California, Davis
One Shields Avenue
Davis, CA 95616
Phone: 415-763-5476
AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307

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

2011-08-11 Thread David Winsemius


On Aug 11, 2011, at 3:38 AM, Peter Maclean wrote:

How do I move the legend from default position (right and within the  
plot) to the "bottomleft" of the plot?


interaction.plot(YEAR, ID GROWTH, legend=TRUE, col = 2:7,xlab="Year",
   ylim=c(0,2), ylab="Growth",leg.bty = "o")


You display the code from interaction.plot, make a new function, and  
hack the location code for the legend x and y legend arguments which  
are created as the 'xleg' and 'yleg' arguments internally for  
positioning of the legend() and the text(...trace.label) pringint   
and then you make the call again with your new function. Out of the  
box the function adds extra xlim space on the basis of the value of  
the 'legend' argument to interaction.plot to make sure the legend does  
not get over-run by the the lines. The y positioning is determined  
entirely by the ylim. There is no provision that I see for user- 
supplied positioning arguments. It would be cleaner to add such named  
arguments after the ,... in the argument list, since attempting to  
pass named arguments directly to legend will generate a bunch of  
warnings.


--

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] matrix correlations with different packages

2011-08-11 Thread Jari Oksanen
Dear Veronika,


> I'm calculating matrix correlations with permutation tests and I got this
> funny result.  All correlation coefficients are the same with mantel.test
> {ncf} and pcol {simba} but the two functions yield dramatically different
> p-values (using the same number of permutations). Could anyone please
> enlighten me what is causing the difference and which result I can trust?

I haven't used either of these functions, but I looked at the code (yes,
this is open source and you can see how things are done). It looks to me
that package 'ncf' does the permutations in the correct way: it takes a
square matrix and permutes its rows and columns, both in the same way
(dmat2[trek,trek] is the line). On the other hand, it seems that 'simba'
does not do things correctly, but it takes the lower triangle of
(dis)similarities as one long vector and permutes them freely disregarding
the original observations (rows, columns). Without knowing what kind of
results you got, I'd go for 'ncf' way of permutations (like I did in vegan).

Cheers, Jari Oksanen

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


Re: [R] plotrix update

2011-08-11 Thread Jim Lemon

On 08/11/2011 11:19 AM, Jesse Brown wrote:

I've run across what I think is a small bug in the plotrix package.
I've tried to contact the maintainer (Jim Lemon) directly but email is
returned 'undeliverable' at the provided address.
What is the best method to push a patch to a CRAN package in this case?


Hi Jesse,
You must have an old version (and 3.2-3 has just appeared). I'm still 
here, and you can post any problems direct to me. If it's a good one, 
you may even get a mention for finding it.


Jim

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


Re: [R] Different approach to set up Cohen Kappa

2011-08-11 Thread Jim Lemon

On 08/10/2011 06:38 PM, gavfung wrote:

Hi, I just started learning R, and one of the most frequent thing that I need
to calculate is cohen kappa in my psychology lab and I figure being able to
do inter rater reliability is a great way for me to explore R.  There are
two different scenario in which I need help with. (By the way, I have
installed irr and concord.)

1) In the lab I am working in, we go through transcripts and find certain
words to code, and we usually compare the codes between two raters. In this
case, the two rater can agree (both rater coded "apple" with "A"), have a
mismatch (one rater coded "apple" with "A" but another coded it as "B") or a
miss (a rater coded "apple" with "A" but the other rater did not code it at
all). There are several codes with similar procedures and as the codes are
tallied together, a chart is constructed, similar to the one attached(
http://r.789695.n4.nabble.com/file/n3732320/example1.xls example1.xls )
title "example1.xls." The maroon color represents the cells with data, and
the lavender cells is just the total in each row/column.

My question in this case is How would I calculate the Cohen Kappa for the
cell shaded in maroon?

I would advise not using the cohen.kappa function in the concord 
package, even though it will handle "not coded" responses. The package 
has not been maintained since most of the functions were merged with the 
"irr" package. If the misses were symmetric between the raters, I would 
simply ignore them. It is only when raters differ on misses that you can 
include them without inflating the test statistic. If this example is 
relevant, it might help you:


gf.scores<-matrix(c("A","A","A","A","A","A","A","M","A","M",
 "B","B","B","B","B","B","B","B","M","B","M","B","B","M","B","M",
 "C","C","C","C","C","C","M","C","M","C","M","C","C","M",
 "C","M","C","M"),ncol=2,byrow=TRUE)
gfraters<-rep(1:2,22)
library(e1071)
classAgreement(table(gfraters,gf.scores))

Jim

2)I helped run participants over the summer for a psych summer internship
and after coding them, I will enter the data as shown in the attachment
title "example2.xls (
http://r.789695.n4.nabble.com/file/n3732320/example2.xls example2.xls )
There is also another research assistant that entered the data and I want to
find a way to check whether we are reliable or not, and want to calculate
reliability for the following:TimeI, TimeA, TriesI, and TriesA.

Once again, i would need to convert the excel file into csv, but aside from
that, I am lost as to what I need to do.  Any help is appreciated!  Thank
you!

--
View this message in context: 
http://r.789695.n4.nabble.com/Different-approach-to-set-up-Cohen-Kappa-tp3732320p3732320.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] Passing on "groups" argument to xyplot within a plotting function

2011-08-11 Thread Fredrik Karlsson
Hi,

I am constructing a plotting function that I would like to behave like
plotting functions within the lattice package. It takes a "groups" argument,
which I process, and then I would like to pass that argument on to the
xyplot function for the actual plotting. However, what ever I do, get an
error that the variable is missing.

A short illustration:

Given the data set

> names(pb)
[1] "Type""Sex" "Speaker" "Vowel"   "IPA" "F0"  "F1"
[8] "F2"  "F3"

and these test functions:

TESTFUN <- function(x,data,groups){

  xyplot(x,data=data,groups=groups)
}

TESTFUN2 <- function(x,data,groups){

  xyplot(x,data=data,groups=substitute(groups))
}

TESTFUN3 <- function(x,data,groups){
  groups <- eval(substitute(groups), data, environment(x))

  xyplot(x,data=data,groups=groups)
}

I fail to get "groups" to be passed on to xyplot correctly:

> TESTFUN(F1 ~ F2,data=pb,groups=Type)
Error in eval(expr, envir, enclos) : object 'groups' not found
> TESTFUN2(F1 ~ F2,data=pb,groups=Type)
Error in prepanel.default.function(groups = groups, x = c(2280L, 2400L,  :
  object 'groups' not found
> TESTFUN3(F1 ~ F2,data=pb,groups=Type)
Error in eval(expr, envir, enclos) : object 'groups' not found

Please help me understand what I am doing wrong.

/Fredrik

-- 
"Life is like a trumpet - if you don't put anything into it, you don't get
anything out of it."

[[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] To import data to R from Excel

2011-08-11 Thread Petr PIKAL
Hi
> 
> In Excel, make sure that your data has a format that corresponds to an R 

> data frame (first row with column names, consistent column size and data 
type).
> Export your .XLS worksheet as .CSV file (mydata.csv).
> In R, read it into a data frame with
> 
> > read.csv( "mydata.csv" ) 

Another option is simple copy/paste way.

In Excel select the data area you want to transfer (preferably formatted 
like stated above.
Press Ctrl-C
Change to R
In R command window write 

my.data.frame <- read.delim("clipboard",...further options according to 
your locale...)

Regards
Petr

> 
> >From here, you shold be able to reshapte the data in a way that you can 

> draw your boxplot.
> 
> Rgds,
> Rainer
> 
> 
> On Thursday 11 August 2011 11:29:23 Blessy chemmannur Francis wrote:
> > Sir,
> >   I am a beginner in R language. I want to import data from 
excel to
> > R. My data contains not only numeric values but also string values.I 
want to
> > draw a boxplot graph . I can't import or write this string data. it is
> > essential for my graph.Please give me a suggestion for This.
> >Thanking You,
> > 
> > 
> > BLESSY.C.F.
> > 
> >[[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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Sequential Naming of ggplot .pngs using plyr

2011-08-11 Thread Matthew Dowle

Hi Justin,

In data.table 1.6.1 there was this news item :

oj's environment is now consistently reused so
that local variables may be set which persist
from group to group; e.g., incrementing a group
counter :
DT[,list(z,groupInd<-groupInd+1),by=x]

One of the reasons data.table is fast is that there is no function
run per group. It's just that j expression. That's run in the same
persistent environment for each group, so you can do things
like increment a group counter within it.

If your data were in 'long' format (data.table prefers long format,
like a database) it might be something like (the ggplot line is untested) :

ctr = 1
DT[,{ 
png(file=paste('/tmp/plot_number_',ctr,'.png',sep=''),height=8.5,width=11,units='in',pointsize=9,res=300)
  print(ggplot(aes(x=site,y=val))+geom_boxplot()+opts(title=paste('plot 
number',ctr,sep=' ')))
  dev.off()
  ctr<-ctr+1 },
   by=site]

Btw, there was a new feature in 1.6.3, where you can subassign
into data.table 500 times faster than <-.  See the NEWS from
1.6.3 for an example :

http://datatable.r-forge.r-project.org/

Matthew


"Justin Haynes"  wrote in message 
news:CAFaj53kjqy=1bJy+iLjeeLYKgvx=rte2h_ha24pt20wqvch...@mail.gmail.com...
> Thanks Ista,
>
> In my real code that is exactly what I'm doing, but I want to prepend the
> names with a sequential number for easier reference once the pngs are 
> made.
>
> My initial thought was to add the sequential number to the data before
> sending it to plyr and drawing it out there, but that seems like an
> excessive extra step when I have 1e6 - 1e7 rows.
>
>
> Justin
>
>
> On Wed, Aug 10, 2011 at 2:42 PM, Ista Zahn 
> wrote:
>
>> Hi Justin,
>>
>> On Wed, Aug 10, 2011 at 5:04 PM, Justin Haynes  wrote:
>> > If I have data:
>> >
>> >
>> dat<-data.frame(a=rnorm(20),b=rnorm(20),c=rnorm(20),d=rnorm(20),site=rep(letters[5:8],each=5))
>> >
>> > And want to plot like this:
>> >
>> > ctr<-1
>> > for(i in c('a','b','c','d')){
>> >png(file=paste('/tmp/plot_number_',ctr,'.png',sep=''),height=8.5,
>> > width=11,units='in',pointsize=9,res=300)
>> >print(ggplot(dat[,names(dat) %in%
>> >
>> c('site',i)],aes(x=factor(site),y=dat[,i]))+geom_boxplot()+opts(title=paste('plot
>> > number',ctr,sep=' ')))
>> >dev.off()
>> >ctr<-ctr+1
>> > }
>> >
>> > Is there a way to do the same naming using plyr (or data.table or 
>> > foreach
>> > which I am not familiar with at all!)?
>>
>> This is not "the same naming", but the same general idea can be
>> achieved with plyr using
>>
>>  d_ply(melt(dat,id.vars='site'),.(variable),function(df) {
>> png(file=paste("plyr_plot", unique(df$variable),
>> ".png"),height=8.5,width=11,units='in',pointsize=9,res=300)
>> print(ggplot(df,aes(x=factor(site),y=value))+geom_boxplot())
>> dev.off()
>>  })
>>
>> I'm not up to speed on .parallel, foreach etc., so I'l leave the rest
>> to someone else.
>>
>> Best,
>> Ista
>> >
>> > m.dat<-melt(dat,id.vars='site')
>> > ddply(m.dat,.(variable),function(df)
>> > print(ggplot(df,aes(x=factor(site),y=value))+geom_boxplot()+ ..?)
>> >
>> > And better yet, is there a way to do it using .parallel=T?
>> >
>> > Faceting is not really an option (unless I can facet onto multiple 
>> > pages
>> of
>> > a pdf or something) because these need to go into reports as 
>> > individually
>> > labelled and titled plots.
>> >
>> >
>> > As a bit of a corollary, is it really worth the headache to resolve 
>> > this
>> if
>> > I am only using melt/plyr to split on the four letter variables? With a
>> > larger set of data (1e6 rows), the melt/plyr version takes a 
>> > significant
>> > amount of time but .parallel=T drops the time significantly.  Is the
>> right
>> > answer a foreach loop and can I do that with the increasing counter? (I
>> > haven't gotten beyond Hadley's .parallel feature in my parallel R
>> > dealings.)
>> >
>> >>
>> >
>> dat<-data.frame(a=rnorm(1e6),b=rnorm(1e6),c=rnorm(1e6),d=rnorm(1e6),site=rep(letters[5:8],each=2.5e5))
>> >> ctr<-1
>> >> system.time(for(i in c('a','b','c','d')){
>> > + png(file=paste('/tmp/plot_number_',ctr,'.png',sep=''),height=8.5,
>> > width=11,units='in',pointsize=9,res=300)
>> > + print(ggplot(dat[,names(dat) %in%
>> >
>> c('site',i)],aes(x=factor(site),y=dat[,i]))+geom_boxplot()+opts(title=paste('plot
>> > number',ctr,sep=' ')))
>> > + dev.off()
>> > + ctr<-ctr+1
>> > + })
>> >   user  system elapsed
>> >  54.630   0.120  54.843
>> >
>> >> system.time(
>> > + ddply(melt(dat,id.vars='site'),.(variable),function(df) {
>> > +
>> >
>> png(file='/tmp/plyr_plot.png',height=8.5,width=11,units='in',pointsize=9,res=300)
>> > + print(ggplot(df,aes(x=factor(site),y=value))+geom_boxplot())
>> > + dev.off()
>> > + },.parallel=F)
>> > + )
>> >   user  system elapsed
>> >  58.400.13   58.63
>> >
>> >> system.time(
>> > + ddply(melt(dat,id.vars='site'),.(variable),function(df) {
>> > +
>> >
>> png(file='/tmp/plyr_plot.png',height=8.5,width=

Re: [R] To import data to R from Excel

2011-08-11 Thread Rainer Schuermann
In Excel, make sure that your data has a format that corresponds to an R data 
frame (first row with column names, consistent column size and data type).
Export your .XLS worksheet as .CSV file (mydata.csv).
In R, read it into a data frame with

> read.csv( "mydata.csv" ) 

>From here, you shold be able to reshapte the data in a way that you can draw 
>your boxplot.

Rgds,
Rainer


On Thursday 11 August 2011 11:29:23 Blessy chemmannur Francis wrote:
> Sir,
>   I am a beginner in R language. I want to import data from excel to
> R. My data contains not only numeric values but also string values.I want to
> draw a boxplot graph . I can't import or write this string data. it is
> essential for my graph.Please give me a suggestion for This.
>Thanking You,
> 
> 
> BLESSY.C.F.
> 
>   [[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] plotrix update

2011-08-11 Thread Prof Brian Ripley

On Thu, 11 Aug 2011, Jesse Brown wrote:


On Thu, Aug 11, 2011 at 12:09 AM, Rolf Turner  wrote:

On 11/08/11 13:19, Jesse Brown wrote:


I've run across what I think is a small bug in the plotrix package.
I've tried to contact the maintainer (Jim Lemon) directly but email is
returned 'undeliverable' at the provided address.
What is the best method to push a patch to a CRAN package in this case?

Thank you,


Jim posted to r-help as recently as 9 August 2011, using the email
address that is given by maintainer("plotrix").

Are you sure you didn't somehow mis-specify the address?

   cheers,

       Rolf Turner



No. In fact I tried twice. I've sent yet another to that address this
evening. If that fails I will post something to this list (it is a
minimal change).


There really is no point in doing that.  Only the maintainer can 
change a package and submit an update, with three exceptions:


(1) CRAN is convinced that the maintainer has disappeared when the 
package would be orphaned/archived.  That is not done lightly, and we 
have often managed to track down maintainers who have moved without 
informing CRAN.


(2) There is written confirmation from both parties of a switch in 
maintainer.


(3) The CRAN team do put up NMUs (non-maintainer updates) that are 
urgently needed to keep things working (usually only after a 
non-response from the maintainer).



I had no idea about the maintainer() function - very useful to know (I
was using the CRAN web page)


Which is likely to be more accurate, since it is taken directly from 
the latest version of the package.




Thanks,

Jesse

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



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] legend position in interaction.plot

2011-08-11 Thread Peter Maclean
How do I move the legend from default position (right and within the plot) to 
the "bottomleft" of the plot?
 
interaction.plot(YEAR, ID GROWTH, legend=TRUE, col = 2:7,xlab="Year", 
   ylim=c(0,2), ylab="Growth",leg.bty = "o")

Peter Maclean
Department of Economics
UDSM

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

2011-08-11 Thread Bókony Veronika

Dear all,

I'm calculating matrix correlations with permutation tests and I got this 
funny result.  All correlation coefficients are the same with mantel.test 
{ncf} and pcol {simba} but the two functions yield dramatically different 
p-values (using the same number of permutations). Could anyone please 
enlighten me what is causing the difference and which result I can trust? 
(My matrices are not hdist objects so please don't recommend using 
mantel.rtest {ade4} instead :)


Thanks a lot!

Veronika Bókony PhD
Dept. of Limnology
University of Pannonia
Pf. 158. Veszprém H-8201
Hungary
vbok...@almos.uni-pannon.hu

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