[R] Manipulating Arrays

2009-10-10 Thread ampc

Manipulating Arrays
Using the below data:

df <- structure(list(dim1 = structure(c(1L, 3L, 1L, 4L, 1L, 2L, 2L, 
2L, 3L, 1L, 4L, 3L, 4L, 4L, 3L, 2L), .Label = c("a1", "a2", "a3", 
"a4"), class = "factor"), dim2 = structure(c(2L, 1L, 2L, 2L, 
4L, 3L, 1L, 3L, 1L, 3L, 2L, 4L, 3L, 4L, 1L, 4L), .Label = c("b1", 
"b2", "b3", "b4"), class = "factor"), dim3 = structure(c(1L, 
4L, 3L, 2L, 1L, 1L, 2L, 4L, 3L, 2L, 2L, 3L, 3L, 1L, 4L, 4L), .Label =
c("c1", 
"c2", "c3", "c4"), class = "factor"), dim4 = structure(c(2L, 
4L, 1L, 3L, 3L, 1L, 2L, 2L, 3L, 2L, 3L, 4L, 1L, 4L, 1L, 4L), .Label =
c("d1", 
"d2", "d3", "d4"), class = "factor"), value = c(33L, 28L, 97L, 
64L, 95L, 64L, 21L, 76L, 93L, 50L, 30L, 7L, 89L, 57L, 27L, 14L
)), .Names = c("dim1", "dim2", "dim3", "dim4", "value"), class =
"data.frame", row.names = c(NA, 
-16L))

library(reshape)
arr <- cast(df, dim1~dim2~dim3~dim4, sum)

> dim(arr)
[1] 4 4 4 4

How do I manipulate this array?


1. Can I add an extra element in the first dimension using the existing
dimensions? As in a dataframe? Such as (The below does not work)

> arr[5,,,] <- arr[1,,,] * 2 + 1 
Error in arr[5, , , ] <- arr[1, , , ] * 2 + 1 : subscript out of bounds

2. How do I remove say the 2 element of the first dimension and have other
elements re-arranged in the logical way 
i.e deleting arr[2,,,] means arr[3,,,] becomes arr[2,,,]; and arr[4,,,]
becomes arr[3,,,]
(again the below does not work)
arr[2,,,] <- NULL

Error in arr[2, , , ] <- NULL : 
  number of items to replace is not a multiple of replacement length


-- 
View this message in context: 
http://www.nabble.com/Manipulating-Arrays-tp25838608p25838608.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] How do I reverse the digits of a number

2009-10-10 Thread tom_p

Hi All,

Thanks for your help.  I need to reverse the digits of a number (unknown
lenght).  Example 1234->4321

Tom
-- 
View this message in context: 
http://www.nabble.com/How-do-I-reverse-the-digits-of-a-number-tp25838410p25838410.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] Matching Dates Closest without going over

2009-10-10 Thread ampc

Thanks Gabor. That was exactly what I was looking for. 

Ampy





ampc wrote:
> 
> Hi,
> 
> I have 2 date vectors d1 and d2. 
> 
> d1 <- structure(c(14526, 14495, 14464, 14433, 14402, 14371, 14340, 14309,
> 14278, 14247, 14216, 14185), class = "Date")
> d2 <- structure(c(14526, 14509, 14488, 14466, 14453, 14441, 14396, 14388,
> 14343, 14333, 14310, 14281), class = "Date")
> 
> I would like to create another dataframe with columns d1 and d2, where d1
> is the original d1 and d2 is the max(d2) such that d1 > d2. And NA's where
> not applicable.
> (See desired result below)
> 
> Thanks,
> Ampy
> 
> 
> 
> d1
> 2009-10-09
> 2009-09-08
> 2009-08-08
> 2009-07-08
> 2009-06-07
> 2009-05-07
> 2009-04-06
> 2009-03-06
> 2009-02-03
> 2009-01-03
> 2008-12-03
> 2008-11-02
> 
> 
> d2
> 2009-10-09
> 2009-09-22
> 2009-09-01
> 2009-08-10
> 2009-07-28
> 2009-07-16
> 2009-06-01
> 2009-05-24
> 2009-04-09
> 2009-03-30
> 2009-03-07
> 2009-02-06
> 
> result:
> 
> d1 d2
> 2009-10-09 2009-10-09
> 2009-09-08 2009-09-01
> 2009-08-08 2009-07-28
> 2009-07-08 2009-06-01
> 2009-06-07 2009-06-01
> 2009-05-07 2009-04-09
> 2009-04-06 2009-03-30
> 2009-03-06 2009-02-06
> 2009-02-03 NA
> 2009-01-03 NA
> 2008-12-03 NA
> 2008-11-02 NA
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Matching-Dates-Closest-without-going-over-tp25830902p25838149.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] field names as function parameters

2009-10-10 Thread tdm

Hi,

I am passing a data frame and field name to a function. I've figured out how
I can create the formula based on the passed in field name, but I'm
struggling to create a vector based in that field.

for example if I hard code with the actual field name

Y = df$Target, everything works fine.

but if I use the passed in parameter name, it doesn't give me what I want,

Y = df$mytarget


Here is the function,

# trying to pass field name to a function
logistictest <- function(df,mytarget)
{

#library for AUC calculation
library(caTools)

#build logistic model
mytarget <- deparse(substitute(mytarget)) 
myformula <- paste(mytarget," ~ .")
myformula <- deparse(substitute(myformula)) 
logistic_reg <- glm(myformula , data=df, family=binomial(link="logit"))
print("model build OK")

#score up
scores <- predict(logistic_reg, type="response", df)
print("model scored OK")

#calc AUC
Y = df$mytarget

auc <- colAUC(scores,Y)
print("auc calculated OK")

}

logistictest(df=trainset,mytarget=Target)


[1] "model build OK"
[1] "model scored OK"
Error in as.vector(x, mode) : invalid 'mode' argument

-- 
View this message in context: 
http://www.nabble.com/field-names-as-function-parameters-tp25838606p25838606.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Creating a Clustered-Stacked Column Chart

2009-10-10 Thread zhijie zhang
  Thanks for your ideas and suggestions. I need to point out that most of us
will create the Clustered-Stacked Column Chart in the matrix layout as David
gave above, but here i hope to display the graph side by side as the example
in the link http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html,
which may be not a good method to display the information.
   Actually, i browsed the lattice package and re-run the examples in its
help before posting this question. As John said above, "I don't think I've
seen an R version, probably because the technique is not very good for
displaying data.".
  Following Peter's suggestion, i browsed the layout= argument in the link
http://www.stat.ucl.ac.be/ISdidactique/Rhelp/library/lattice/html/xyplot.html
and
tried it, but cannot successfully get the correct graph.

library(lattice)
barchart(Titanic, scales = list(x = "free"),auto.key = list(title =
"Survived"))
barchart(Titanic, scales = list(x = "free"),auto.key = list(title =
"Survived"),layout=c(2,1))  #missed the children's graph
barchart(Titanic, scales = list(x = "free"),auto.key = list(title =
"Survived"),layout=c(1,2))  #missed the children's graph
  Thanks a lot.

2009/10/10 Peter Ehlers 

> I think you're missing the point. David _did_ show you how
> to create a graph showing 4 clusters of stacked barcharts.
> If you want them side-by-side instead of in the matrix
> layout David gave, use the layout= argument.
>
>  -Peter Ehlers
>
> zhijie zhang wrote:
>
>>  Hi David,
>>  Your codes are for stacked chart. Actually, i hope to Create a
>> Clustered-Stacked Column Chart, which means that a chart will combine the
>> traits of stacked chart and clustered chart, see the example in the page
>> http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html.
>>  Thanks.
>> 2009/10/10 David Winsemius 
>>
>>   library(lattice)
>>> barchart(Titanic, scales = list(x = "free"),
>>> auto.key = list(title = "Survived"))
>>>
>>> Or if you prefer vertical:
>>>
>>> barchart(Titanic, scales = list(x = "free"),
>>>auto.key = list(title = "Survived"), horizontal=FALSE)
>>>
>>> There are adjustments available to the space between bars.
>>>
>>> barchart(Titanic, scales = list(x = "free"),
>>>auto.key = list(title = "Survived"), horizontal=FALSE,
>>> box.ratio=100)
>>>
>>>
>>>
>>> On Oct 9, 2009, at 9:57 PM, zhijie zhang wrote:
>>>
>>>  Thanks a lot. Maybe someone else has the method to solve that.
>>>

 2009/10/9 John Kane 

  I don't think I've seen an R version, probably because the technique is

> not
> very good for displaying data.
>
> Have a look at http://chartsgraphs.wordpress.com/tag/r-and-excel/ for
> an
> alternative method of displaying the data using lattice.
>
> --- On Fri, 10/9/09, zhijie zhang  wrote:
>
> From: zhijie zhang 
>
>> Subject: [R] Creating a Clustered-Stacked Column Chart
>> To: r-h...@stat.math.ethz.ch
>> Received: Friday, October 9, 2009, 5:31 AM
>> Hi all,
>>  In R, is there some functions or ways to
>> create a Clustered-Stacked
>> Column Chart as the example in the following page
>> http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html?
>>  I have browsed the R Graph Gallery (
>>
>> http://addictedtor.free.fr/graphiques/)
>
> and searched the R site, and didnot find an appropriate
>> method to do it.
>>  Anybody has met this problem before?
>>  Thanks a lot.
>>
>>  [[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.
>>
>>
>>   __
> Get the name you've always wanted @ymail.com or @rocketmail.com! Go to
> http://ca.promos.yahoo.com/jacko/
>
>
>   [[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.

 David Winsemius, MD
>>> Heritage Laboratories
>>> West Hartford, CT
>>>
>>>
>>>
>>[[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting

Re: [R] lattice auto.key drop unused levels

2009-10-10 Thread Deepayan Sarkar
On Sat, Oct 10, 2009 at 5:51 PM, Peter Ehlers  wrote:
> The key will show the levels of the 'groups' factor. So you will
> have to ensure that the factor fed to groups has the levels
> that you want displayed. ?xyplot explicitly states that
> drop.unused.levels will NOT do that for you.
>
> (Didn't Deepayan just answer something like this?)

Yes:

https://stat.ethz.ch/pipermail/r-help/2009-October/214516.html

and the Lattice book has a longer discussion (in particular section 9.2.5).

-Deepayan


>  -Peter Ehlers
>
> Jacob Wegelin wrote:
>>
>> The following code produces a legend ("key") that mentions the unused
>> levels of Block.
>>
>> library(MEMSS)
>> xyplot(yield~nitro, subset=(Block=="I" | Block=="II"), data=Oats,
>> group=Block, auto.key=T)
>>
>> and adding "drop.unused.levels=T" does not fix it. And in fact even
>> the following does not solve the problem:
>>
>>  xyplot(yield~nitro, data=Oats[Oats$Block=="I" | Oats$Block=="II",],
>> group=Block, auto.key=T)
>>
>> The following workaround solves it, but seems inelegant:
>>
>> junk<-Oats[Oats$Block=="I" | Oats$Block=="II",]
>> junk$Block<-factor(as.character(junk$Block))
>> xyplot(yield~nitro, group=Block, data=junk, auto.key=T)
>>
>> What is the elegant or "proper R thinking" way to do this? That is, I
>> want to get a key that only mentions the levels of Block that are used
>> in the plot.
>>
>> Thanks
>>
>> Jacob A. Wegelin
>> Assistant Professor
>> Department of Biostatistics
>> Virginia Commonwealth University
>> 730 East Broad Street Room 3006
>> P. O. Box 980032
>> Richmond VA 23298-0032
>> U.S.A.
>> E-mail: jwege...@vcu.edu
>> URL: http://www.people.vcu.edu/~jwegelin

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


Re: [R] Running R scripts from a GUI interface

2009-10-10 Thread Gabor Grothendieck
The last version of fgui was produced only 6 months ago so its
relatively recent and there was a JSS paper on it published during
that time frame as well.  Send an email to the fgui package maintainer
if you want to know what he intends.  The ggenericwidget function in
gWidgets is very similar fgui as already mentioned so that would give
you an alternative.

The source code to R is freely available and Writing R Extensions
manual discusses writing front ends to R but you were looking for
something simple and none of that fits in with being simple.

If you want something self contained forget about R, fgui, etc. and
use another language.

On Sat, Oct 10, 2009 at 10:38 PM, Jason Rupert  wrote:
> Thank you for recommending fgui.  This package looks very promising.
>
> By any chance do you know if it is still being maintained?
>
> The URL provided for the packaged does not appear to be functional, so I was 
> curious if this package is going to be maintained going forward.
>
>
> Also, do you know, once the GUI is in the format you desire, to then "export" 
> the functionality so that you do not have to have the complete R executable 
> and appropriate packages installed.  That is, export a stand-alone TCL/TK GUI 
> and associated libraries that contain the functionality so that the complete 
> R executable is not necessary.
>
> Thanks again for any insights and I continue to be impressed with the 
> capability of the contributed packages.  These really are helpful for 
> accelerating the development of useful code.
>
>
>
>
>
> --- On Sat, 10/10/09, Gabor Grothendieck  wrote:
>
>> From: Gabor Grothendieck 
>> Subject: Re: [R] Running R scripts from a GUI interface
>> To: "Jason Rupert" 
>> Cc: R-help@r-project.org
>> Date: Saturday, October 10, 2009, 7:49 AM
>> There are many approaches to GUIs in
>> R but for something quick, which
>> I gather is your main aim here, have a look at the fgui
>> package and
>> also the very similar ggenericwidget function in the
>> gWidgets package.
>>
>> On Sat, Oct 10, 2009 at 1:05 AM, Jason Rupert 
>> wrote:
>> > It appears several that of my scripts are beginning to
>> reaching maturity, so I am curious if it is possible to add
>> an external GUI to run the scripts from this simplified GUI
>> interface.
>> >
>> > The scripts are fairly rudimentary so the GUI only
>> needs a few radial buttons and a could of numeric fields.
>> >
>> > I am curious if there is a typical approach for
>> developing a GUI to run R scripts or to export R scripts in
>> a DLL or other format so that they can be run from such a
>> GUI.
>> >
>> > I also have not settled on a GUI development language
>> so any suggestions there are also very much appreciated.
>> >
>> > Thank you again for any feedback and insights,
>> especially if there is a blog or book that covers these
>> topics.
>> >
>> > __
>> > R-help@r-project.org
>> mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide 
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained,
>> reproducible code.
>> >
>>
>
>
>
>

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


Re: [R] passing field name parameter to function

2009-10-10 Thread David Winsemius


On Oct 10, 2009, at 9:27 PM, tdm wrote:



Hi,

I am passing a data frame and field name to a function. I've figured  
out how

I can create the formula based on the passed in field name, but I'm
struggling to create a vector based in that field.

for example if I hard code with the actual field name

Y = df$Target, everything works fine.

but if I use the passed in parameter name, it doesn't give me what I  
want,


Y = df$mytarget


Here is the function,

# trying to pass field name to a function
logistictest <- function(df,mytarget)
{

#library for AUC calculation
library(caTools)

#build logistic model
mytarget <- deparse(substitute(mytarget))
myformula <- paste(mytarget," ~ .")
myformula <- deparse(substitute(myformula))
logistic_reg <- glm(myformula , data=df,  
family=binomial(link="logit"))

print("model build OK")

#score up
scores <- predict(logistic_reg, type="response", df)
print("model scored OK")

#calc AUC
Y = df$mytarget

auc <- colAUC(scores,Y)
print("auc calculated OK")

}

logistictest(df=trainset,mytarget=Target)


A further comment. There is no object "Target" (or if there is, it is  
created by code that you have not included).  There is only a name  
"Target" for a list element in the object "df". The formalism df 
$Target is really syntactic window dressing for df$"Target" and it  
only works because $ is designed to extract named elements from within  
an object that is visible to to the interpreter at this level. (Sorry  
for imprecise language, but that what noobs like me end up resorting  
to.)





[1] "model build OK"


Actually that is not tested. I suspect that if you wrote:   
print(logistic_reg) ...  it would be empty.



[1] "model scored OK"
Error in as.vector(x, mode) : invalid 'mode' argument
--


David Winsemius, MD
Heritage Laboratories
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] Running R scripts from a GUI interface

2009-10-10 Thread Jason Rupert
Thank you for recommending fgui.  This package looks very promising. 

By any chance do you know if it is still being maintained? 

The URL provided for the packaged does not appear to be functional, so I was 
curious if this package is going to be maintained going forward. 


Also, do you know, once the GUI is in the format you desire, to then "export" 
the functionality so that you do not have to have the complete R executable and 
appropriate packages installed.  That is, export a stand-alone TCL/TK GUI and 
associated libraries that contain the functionality so that the complete R 
executable is not necessary.  

Thanks again for any insights and I continue to be impressed with the 
capability of the contributed packages.  These really are helpful for 
accelerating the development of useful code.





--- On Sat, 10/10/09, Gabor Grothendieck  wrote:

> From: Gabor Grothendieck 
> Subject: Re: [R] Running R scripts from a GUI interface
> To: "Jason Rupert" 
> Cc: R-help@r-project.org
> Date: Saturday, October 10, 2009, 7:49 AM
> There are many approaches to GUIs in
> R but for something quick, which
> I gather is your main aim here, have a look at the fgui
> package and
> also the very similar ggenericwidget function in the
> gWidgets package.
> 
> On Sat, Oct 10, 2009 at 1:05 AM, Jason Rupert 
> wrote:
> > It appears several that of my scripts are beginning to
> reaching maturity, so I am curious if it is possible to add
> an external GUI to run the scripts from this simplified GUI
> interface.
> >
> > The scripts are fairly rudimentary so the GUI only
> needs a few radial buttons and a could of numeric fields.
> >
> > I am curious if there is a typical approach for
> developing a GUI to run R scripts or to export R scripts in
> a DLL or other format so that they can be run from such a
> GUI.
> >
> > I also have not settled on a GUI development language
> so any suggestions there are also very much appreciated.
> >
> > Thank you again for any feedback and insights,
> especially if there is a blog or book that covers these
> topics.
> >
> > __
> > R-help@r-project.org
> mailing list
> > https://stat.ethz.ch/mailman/listinfo/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] lattice auto.key drop unused levels

2009-10-10 Thread Jacob Wegelin
On Sat, Oct 10, 2009 at 8:51 PM, Peter Ehlers  wrote:
> The key will show the levels of the 'groups' factor. So you will
> have to ensure that the factor fed to groups has the levels
> that you want displayed. ?xyplot explicitly states that
> drop.unused.levels will NOT do that for you.

So the answer seems to be that there is no way to drop the levels
without bypassing the "subset" argument.

The following creates the desired effect:

xyplot(yield~nitro, data=Oats[Oats$Block=="I" | Oats$Block=="II" , ] ,
group=Block [, drop=T], auto.key=T)

whereas dropping levels in the "group" argument does not create the
desired effect

xyplot(yield~nitro, subset=(Block=="I" | Block=="II"), data=Oats,
group=Block [, drop=T], auto.key=T)

Jacob Wegelin

>  -Peter Ehlers
>
> Jacob Wegelin wrote:
>>
>> The following code produces a legend ("key") that mentions the unused
>> levels of Block.
>>
>> library(MEMSS)
>> xyplot(yield~nitro, subset=(Block=="I" | Block=="II"), data=Oats,
>> group=Block, auto.key=T)
>>
>> and adding "drop.unused.levels=T" does not fix it. And in fact even
>> the following does not solve the problem:
>>
>>  xyplot(yield~nitro, data=Oats[Oats$Block=="I" | Oats$Block=="II",],
>> group=Block, auto.key=T)
>>
>> The following workaround solves it, but seems inelegant:
>>
>> junk<-Oats[Oats$Block=="I" | Oats$Block=="II",]
>> junk$Block<-factor(as.character(junk$Block))
>> xyplot(yield~nitro, group=Block, data=junk, auto.key=T)
>>
>> What is the elegant or "proper R thinking" way to do this? That is, I
>> want to get a key that only mentions the levels of Block that are used
>> in the plot.

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


Re: [R] passing field name parameter to function

2009-10-10 Thread David Winsemius

You code is not reproducible.

Take a look at this much simpler example:

> a
  x y xx xxx
1 1 4  8  12
2 2 5  9  13
3 3 6 10  14
4 4 7 11  15
5 1 4  8  12
6 2 5  9  13
7 3 6 10  14
8 4 7 11  15

> funct <- function(df, colnm) print(df[, colnm])

> funct(a, "xx")
[1]  8  9 10 11  8  9 10 11
#--
> fortune(106)

If the answer is parse() you should usually rethink the question.
   -- Thomas Lumley
  R-help (February 2005)
#---
Further simple example:

(use dput(a) to produce the structure object:)


a <- structure(list(x = c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L), y = c(4L,
5L, 6L, 7L, 4L, 5L, 6L, 7L), xx = c(8L, 9L, 10L, 11L, 8L, 9L,
10L, 11L), xxx = c(12L, 13L, 14L, 15L, 12L, 13L, 14L, 15L)), .Names =  
c("x",

"y", "xx", "xxx"), row.names = c(NA, -8L), class = "data.frame")

lmfunct <- function(df, idvar, dvar) lm( as.formula( paste(dvar, " ~  
", idvar, sep="") ), data=df)

lmfunct(a, "x", "y")

---
Call:
lm(formula = as.formula(paste(dvar, " ~ ", idvar, sep = "")), data  
= df)


Coefficients:
(Intercept)x
  31

--
david

On Oct 10, 2009, at 9:27 PM, tdm wrote:



Hi,

I am passing a data frame and field name to a function. I've figured  
out how

I can create the formula based on the passed in field name, but I'm
struggling to create a vector based in that field.

for example if I hard code with the actual field name

Y = df$Target, everything works fine.

but if I use the passed in parameter name, it doesn't give me what I  
want,


Y = df$mytarget


Here is the function,

# trying to pass field name to a function
logistictest <- function(df,mytarget)
{

#library for AUC calculation
library(caTools)

#build logistic model
mytarget <- deparse(substitute(mytarget))
myformula <- paste(mytarget," ~ .")
myformula <- deparse(substitute(myformula))
logistic_reg <- glm(myformula , data=df,  
family=binomial(link="logit"))

print("model build OK")

#score up
scores <- predict(logistic_reg, type="response", df)
print("model scored OK")

#calc AUC
Y = df$mytarget

auc <- colAUC(scores,Y)
print("auc calculated OK")

}

logistictest(df=trainset,mytarget=Target)


[1] "model build OK"
[1] "model scored OK"
Error in as.vector(x, mode) : invalid 'mode' argument
--
View this message in context: 
http://www.nabble.com/passing-field-name-parameter-to-function-tp25840014p25840014.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.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] How do I reverse the digits of a number

2009-10-10 Thread Ben Bolker



tom_p wrote:
> 
> Hi All,
> 
> Thanks for your help.  I need to reverse the digits of a number (unknown
> lenght).  Example 1234->4321
> 
> Tom
> 

> z <- 4321

> as.numeric(paste(rev(strsplit(as.character(z),"")[[1]]),collapse=""))
[1] 1234

-- 
View this message in context: 
http://www.nabble.com/How-do-I-reverse-the-digits-of-a-number-tp25838410p25840085.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] passing field name parameter to function

2009-10-10 Thread jim holtman
You need to understand how accessing elements of a dataframe happen,
especially the '[[' operator (?"[[")

x <- function(dataFrame, name) dataFrame[[name]]

On Sat, Oct 10, 2009 at 9:27 PM, tdm  wrote:
>
> Hi,
>
> I am passing a data frame and field name to a function. I've figured out how
> I can create the formula based on the passed in field name, but I'm
> struggling to create a vector based in that field.
>
> for example if I hard code with the actual field name
>
> Y = df$Target, everything works fine.
>
> but if I use the passed in parameter name, it doesn't give me what I want,
>
> Y = df$mytarget
>
>
> Here is the function,
>
> # trying to pass field name to a function
> logistictest <- function(df,mytarget)
> {
>
> #library for AUC calculation
> library(caTools)
>
> #build logistic model
> mytarget <- deparse(substitute(mytarget))
> myformula <- paste(mytarget," ~ .")
> myformula <- deparse(substitute(myformula))
> logistic_reg <- glm(myformula , data=df, family=binomial(link="logit"))
> print("model build OK")
>
> #score up
> scores <- predict(logistic_reg, type="response", df)
> print("model scored OK")
>
> #calc AUC
> Y = df$mytarget
>
> auc <- colAUC(scores,Y)
> print("auc calculated OK")
>
> }
>
> logistictest(df=trainset,mytarget=Target)
>
>
> [1] "model build OK"
> [1] "model scored OK"
> Error in as.vector(x, mode) : invalid 'mode' argument
> --
> View this message in context: 
> http://www.nabble.com/passing-field-name-parameter-to-function-tp25840014p25840014.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

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


[R] passing field name parameter to function

2009-10-10 Thread tdm

Hi, 

I am passing a data frame and field name to a function. I've figured out how
I can create the formula based on the passed in field name, but I'm
struggling to create a vector based in that field. 

for example if I hard code with the actual field name 

Y = df$Target, everything works fine. 

but if I use the passed in parameter name, it doesn't give me what I want, 

Y = df$mytarget 


Here is the function, 

# trying to pass field name to a function 
logistictest <- function(df,mytarget) 
{ 

#library for AUC calculation 
library(caTools) 

#build logistic model 
mytarget <- deparse(substitute(mytarget)) 
myformula <- paste(mytarget," ~ .") 
myformula <- deparse(substitute(myformula)) 
logistic_reg <- glm(myformula , data=df, family=binomial(link="logit")) 
print("model build OK") 

#score up 
scores <- predict(logistic_reg, type="response", df) 
print("model scored OK") 

#calc AUC 
Y = df$mytarget 

auc <- colAUC(scores,Y) 
print("auc calculated OK") 

} 

logistictest(df=trainset,mytarget=Target) 


[1] "model build OK" 
[1] "model scored OK" 
Error in as.vector(x, mode) : invalid 'mode' argument 
-- 
View this message in context: 
http://www.nabble.com/passing-field-name-parameter-to-function-tp25840014p25840014.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Creating new variables

2009-10-10 Thread David Winsemius


On Oct 10, 2009, at 7:49 PM, Ashta wrote:


Thanks. This helps. How do I generate P?
Will this work?

p1<-pnorm(mean=0, std=1)
p2<-pnorm(mean=0, std=1)

Seems unlikely. You are not supplying sufficient arguments for the  
pnorm function for one thing. For another I suspect you really want  
the rnorm function and the first argument to it is the number of  
random numbers to return:

Perhaps
p1<-rnorm(200. mean=0, std=1)
p2<-pnorm(200, mean=0, std=1)

x <- cbind(x, v1=ifelse(x[,'p'] > 0.4, 1, 0), v2=ifelse(x[,'2'] >  
0.6, 0,

1))


Jim's suggestion will work but even simpler would be:

x <- cbind(x, v1 = (p1>0.4)+0, v2 = (p2> 0.6)+0 )






If the 'data set' is a dataframe, the following will work:

x$v1 <- ifelse(x$p > 0.4, 1, 0)
x$v2 <- ifelse(x$p > 0.6, 1, 0)

If it is matrix, try

x <- cbind(x, v1=ifelse(x[,'p'] > 0.4, 1, 0), v2=ifelse(x[,'p'] >  
0.6, 1,

2))


On Sat, Oct 10, 2009 at 6:32 PM, jim holtman   
wrote:



If the 'data set' is a dataframe, the following will work:

x$v1 <- ifelse(x$p > 0.4, 1, 0)
x$v2 <- ifelse(x$p > 0.6, 1, 0)

If it is matrix, try

x <- cbind(x, v1=ifelse(x[,'p'] > 0.4, 1, 0), v2=ifelse(x[,'p'] >  
0.6, 1,

2))

If helps a lot if you follow the posting rules and  provide  
commented,

minimal, self-contained, reproducible code.

On Sat, Oct 10, 2009 at 6:04 PM, Ashta  wrote:

Hi all,

I have a data set called x with200 rows  and 12  columns.  I  
want

create  two more columns based on  probability. ie
if p >0 .4 then  v1 =1 else v1=0;
if p >0 .6 then  v2 =1 else v2=0;

Finally x will have 14 variables.

Can any one show me how to do that?

Thanks
Ashta


.

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





--
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?



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


David Winsemius, MD
Heritage Laboratories
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] lattice auto.key drop unused levels

2009-10-10 Thread Peter Ehlers

The key will show the levels of the 'groups' factor. So you will
have to ensure that the factor fed to groups has the levels
that you want displayed. ?xyplot explicitly states that
drop.unused.levels will NOT do that for you.

(Didn't Deepayan just answer something like this?)

 -Peter Ehlers

Jacob Wegelin wrote:

The following code produces a legend ("key") that mentions the unused
levels of Block.

library(MEMSS)
xyplot(yield~nitro, subset=(Block=="I" | Block=="II"), data=Oats,
group=Block, auto.key=T)

and adding "drop.unused.levels=T" does not fix it. And in fact even
the following does not solve the problem:

 xyplot(yield~nitro, data=Oats[Oats$Block=="I" | Oats$Block=="II",],
group=Block, auto.key=T)

The following workaround solves it, but seems inelegant:

junk<-Oats[Oats$Block=="I" | Oats$Block=="II",]
junk$Block<-factor(as.character(junk$Block))
xyplot(yield~nitro, group=Block, data=junk, auto.key=T)

What is the elegant or "proper R thinking" way to do this? That is, I
want to get a key that only mentions the levels of Block that are used
in the plot.

Thanks

Jacob A. Wegelin
Assistant Professor
Department of Biostatistics
Virginia Commonwealth University
730 East Broad Street Room 3006
P. O. Box 980032
Richmond VA 23298-0032
U.S.A.
E-mail: jwege...@vcu.edu
URL: http://www.people.vcu.edu/~jwegelin

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

2009-10-10 Thread jim holtman
try this to get the column output:

cat(x, sep='\n', file='/tempxx.txt')

For the transposed out, do:

write.table(t(x), file="filename.txt", row.names=F, col.names=F)

On Sat, Oct 10, 2009 at 2:09 PM, Eiger  wrote:
>
> Hi, I have a question about "how" write output in a .txt file.
>
> With tihs command, I write permutations of the numbers (1,2,3) in a .txt
> file:
>
>> x<-permn(c(1,2,3))
>> write.table(x, file="filename.txt", row.names=F, col.names=F)
>
> This is output in filename.txt:
>
> 1 1 3 3 2 2
> 2 3 1 2 3 1
> 3 2 2 1 1 3
> 
> Is possible write output trasposed?
> Output:
>
>
>
> etc..
> 
> Is possible write output in a single column?
> Output:
> 1
> 2
> 3
> 1
> 3
> 2
> 3
> 1
> 2
> etc. etc.
> _
>
> Thanks,
> E.
>
>
>
> --
> View this message in context: 
> http://www.nabble.com/permutations-tp25834463p25836847.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

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


Re: [R] Creating new variables

2009-10-10 Thread Jim Holtman
you will have to specify what 'x' is.  I am not sure what you are  
trying to do with the variables you have not defined.

Sent from my iPhone

On Oct 10, 2009, at 19:49, Ashta  wrote:

> Thanks. This helps. How do I generate P?
> Will this work?
>
> p1<-pnorm(mean=0, std=1)
> p2<-pnorm(mean=0, std=1)
>
> x <- cbind(x, v1=ifelse(x[,'p'] > 0.4, 1, 0), v2=ifelse(x[,'2'] >  
> 0.6, 0, 1))
>
>
>
>
>
>
> If the 'data set' is a dataframe, the following will work:
>
> x$v1 <- ifelse(x$p > 0.4, 1, 0)
> x$v2 <- ifelse(x$p > 0.6, 1, 0)
>
> If it is matrix, try
>
> x <- cbind(x, v1=ifelse(x[,'p'] > 0.4, 1, 0), v2=ifelse(x[,'p'] >  
> 0.6, 1, 2))
>
>
> On Sat, Oct 10, 2009 at 6:32 PM, jim holtman   
> wrote:
> If the 'data set' is a dataframe, the following will work:
>
> x$v1 <- ifelse(x$p > 0.4, 1, 0)
> x$v2 <- ifelse(x$p > 0.6, 1, 0)
>
> If it is matrix, try
>
> x <- cbind(x, v1=ifelse(x[,'p'] > 0.4, 1, 0), v2=ifelse(x[,'p'] >  
> 0.6, 1, 2))
>
> If helps a lot if you follow the posting rules and  provide commented,
> minimal, self-contained, reproducible code.
>
> On Sat, Oct 10, 2009 at 6:04 PM, Ashta  wrote:
> > Hi all,
> >
> > I have a data set called x with200 rows  and 12  columns.  I  
> want
> > create  two more columns based on  probability. ie
> >  if p >0 .4 then  v1 =1 else v1=0;
> >  if p >0 .6 then  v2 =1 else v2=0;
> >
> > Finally x will have 14 variables.
> >
> > Can any one show me how to do that?
> >
> > Thanks
> > Ashta
> >
> >
> > .
> >
> >[[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.
> >
>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem that you are trying to solve?
>

[[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] defining a function in the package boot

2009-10-10 Thread Wachtel, Mitchell

Please assist me.
In the package "boot" is a term called "statistic".

what is the r syntax for the mean?

is it, given that the name will be AV:

AV <- function (d,x){mean(x*w)}



Thanks.


Mitchell Wachtel

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


Re: [R] Creating new variables

2009-10-10 Thread Ashta
Thanks. This helps. How do I generate P?
Will this work?

p1<-pnorm(mean=0, std=1)
p2<-pnorm(mean=0, std=1)

x <- cbind(x, v1=ifelse(x[,'p'] > 0.4, 1, 0), v2=ifelse(x[,'2'] > 0.6, 0,
1))






If the 'data set' is a dataframe, the following will work:

x$v1 <- ifelse(x$p > 0.4, 1, 0)
x$v2 <- ifelse(x$p > 0.6, 1, 0)

If it is matrix, try

x <- cbind(x, v1=ifelse(x[,'p'] > 0.4, 1, 0), v2=ifelse(x[,'p'] > 0.6, 1,
2))


On Sat, Oct 10, 2009 at 6:32 PM, jim holtman  wrote:

> If the 'data set' is a dataframe, the following will work:
>
> x$v1 <- ifelse(x$p > 0.4, 1, 0)
> x$v2 <- ifelse(x$p > 0.6, 1, 0)
>
> If it is matrix, try
>
> x <- cbind(x, v1=ifelse(x[,'p'] > 0.4, 1, 0), v2=ifelse(x[,'p'] > 0.6, 1,
> 2))
>
> If helps a lot if you follow the posting rules and  provide commented,
> minimal, self-contained, reproducible code.
>
> On Sat, Oct 10, 2009 at 6:04 PM, Ashta  wrote:
> > Hi all,
> >
> > I have a data set called x with200 rows  and 12  columns.  I want
> > create  two more columns based on  probability. ie
> >  if p >0 .4 then  v1 =1 else v1=0;
> >  if p >0 .6 then  v2 =1 else v2=0;
> >
> > Finally x will have 14 variables.
> >
> > Can any one show me how to do that?
> >
> > Thanks
> > Ashta
> >
> >
> > .
> >
> >[[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.
> >
>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem that you are trying to solve?
>

[[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] many weighted means: is there a simpler way?

2009-10-10 Thread Ozan Bakış
Hi R-users,

I would like to calculate weighted mean of several
variables by two factors where the weight vector is
the same for all variables.

Below, there is a simple example where I have only two
variables: "v1","v2" both weighted by "wt" and my factors
are "gender" and "year".

set.seed(1)
df <- data.frame(gender = rep(c("M", "F"),each = 5),
  year = rep(c(1999, 2000), 5), v1 = rnorm(10,10),
  v2 = rnorm(10,6), wt = runif(10))
df
g <- function(x) weighted.mean(x[, 1], x[, 2])
by(df[,c("v1","wt")],df[,c("year","gender")],g)

I can use as above by command for each variable (v1,v2)
separately but I wonder if there is some simpler way
that yields a table/data frame of weigted means for all
"vi"s where i=1...N.

Thank you very much,
ozan

[[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] Nelder-Mead with output of simplex vertices

2009-10-10 Thread Ravi Varadhan
Ted,

I have written an R function that implements C.T. Kelley's algorithm (described 
in his book).  I have tested this on many problems, smooth and non-smooth, and 
in all my testing, I have found it to be clearly superior to optim's 
Nelder-Mead.  You can easily change this code to look at the evolution of the 
simplex.  I can send this to you, if you are interested.

Ben - can you please send me your translation from NR?  I would like to compare 
it to my function.  Thanks in advance.

Best,
Ravi.



Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvarad...@jhmi.edu


- Original Message -
From: Ben Bolker 
Date: Saturday, October 10, 2009 7:23 pm
Subject: Re: [R] Nelder-Mead with output of simplex vertices
To: r-help@r-project.org


>   I have a pure-R implementation of the N-M simplex translated from
> the C code in Press et al 1994 (Numerical Recipes), instrumented to
> save the progress.  Since I'm not sure of the copyright status (NR's
> code does not allow redistribution, but this is a translation ...) 
> I'll send
> it in separate e-mail.
> 
> 
> Ted.Harding-2 wrote:
> > 
> > Greetings!
> > I want to follow the evolution of a Nelder-Mead function
> > minimisation (a function of 2 variables). Hence each simplex
> > will have 3 vertices.
> > 
> > Therefore I would like to have a function which can output
> > the coordinates of the 3 vertices after each new simplex
> > is generated. However, there seems to be no way (which I can
> > detect) of extracting this information from optim() (the 'trace'
> > argument to 'control' does not seem to have provision for this,
> > according to '?optim', and I have tried it out without success).
> > 
> > I have had a good search through the R resources without finding
> > anything of the kind.
> > 
> > Of course I could write my own implementation of Nelder-Mead in R,
> > and generate the required output in my own way, but I would prefer
> > to learn that this is already been done!
> > 
> > Any suggestions?
> > With thanks,
> > Ted.
> > 
> > 
> > E-Mail: (Ted Harding) 
> > Fax-to-email: +44 (0)870 094 0861
> > Date: 10-Oct-09   Time: 22:26:16
> > -- XFMail --
> > 
> > __
> > R-help@r-project.org mailing list
> > 
> > PLEASE do read the posting guide
> > 
> > and provide commented, minimal, self-contained, reproducible code.
> > 
> > 
> 
> -- 
> View this message in context: 
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> 
> PLEASE do read the posting guide 
> 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] Nelder-Mead with output of simplex vertices

2009-10-10 Thread Ben Bolker


  I have a pure-R implementation of the N-M simplex translated from
the C code in Press et al 1994 (Numerical Recipes), instrumented to
save the progress.  Since I'm not sure of the copyright status (NR's
code does not allow redistribution, but this is a translation ...) I'll send
it in separate e-mail.


Ted.Harding-2 wrote:
> 
> Greetings!
> I want to follow the evolution of a Nelder-Mead function
> minimisation (a function of 2 variables). Hence each simplex
> will have 3 vertices.
> 
> Therefore I would like to have a function which can output
> the coordinates of the 3 vertices after each new simplex
> is generated. However, there seems to be no way (which I can
> detect) of extracting this information from optim() (the 'trace'
> argument to 'control' does not seem to have provision for this,
> according to '?optim', and I have tried it out without success).
> 
> I have had a good search through the R resources without finding
> anything of the kind.
> 
> Of course I could write my own implementation of Nelder-Mead in R,
> and generate the required output in my own way, but I would prefer
> to learn that this is already been done!
> 
> Any suggestions?
> With thanks,
> Ted.
> 
> 
> E-Mail: (Ted Harding) 
> Fax-to-email: +44 (0)870 094 0861
> Date: 10-Oct-09   Time: 22:26:16
> -- XFMail --
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Nelder-Mead-with-output-of-simplex-vertices-tp25838572p25838614.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] debug(sum) error

2009-10-10 Thread Duncan Murdoch

On 10/10/2009 7:00 PM, Another Oneforyou wrote:

Hi,
I'm working through "R-debug-tools.pdf" and on page 7 it describes doing:
Browse[1]> debug(sum) ## Flag sum for debugging
however, when I try this, I get:
Browse[1]> debug(sum)Error in debug(fun) : argument must be a closure
Does anyone know why I get this error, and how to work around it?


debug() only works on regular functions (which are called "closures"). 
sum() is a special built in function, because it is so frequently used, 
and because it needs to be fast.  So you can't debug it.


Whoever wrote those instructions should update them to use a different 
example.  (Google suggests that the document was written in 2002, so 
someone may very well have already done so.)


Duncan

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

2009-10-10 Thread Another Oneforyou

Hi,
I'm working through "R-debug-tools.pdf" and on page 7 it describes doing:
Browse[1]> debug(sum) ## Flag sum for debugging
however, when I try this, I get:
Browse[1]> debug(sum)Error in debug(fun) : argument must be a closure
Does anyone know why I get this error, and how to work around it?
Thanks.   
_
Hotmail: Powerful Free email with security by Microsoft.

[[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] Display more than one plot

2009-10-10 Thread joris meys
Just saw I did something stupid. Both examples create a 2 by 2 grid in
your graph window, so you'll be able to plot 4 graphs in that window.
If you plot only 2 graphs, the lower half of the window will be empty
still. Just check the helpfiles and experiment a bit to get a grip of
how to get which graph where. It's pretty straight forward.

Kind regards
Joris


On Sun, Oct 11, 2009 at 12:50 AM, joris meys  wrote:
> Hi Emkay,
>
> If you want to look at different plots together, you can also plot
> them side by side in the same plot window.
>
> You can specify this using for example:
>        par(mfcol=c(2,2))
> ( see ?par and check mfrow and mfcol)
> or
>        layout(matrix(1:4,2,2))
> (see ?layout and ?matrix)
>
> eg :
> x <- c(1,2,3,4,5,6,7,8,9,0)
> y <- c(1,2,3,4,5,6,7,8,9,0)
> z <- c(8,7,6,5,4,3,2,1,0,9)
>
> par(mfcol=c(2,2))
> plot(x,y)
> plot(x,z)
>
> Kind regards
> Joris
>
> On Sat, Oct 10, 2009 at 4:51 AM, emkayenne
>  wrote:
>>
>> Nobody? :-(
>>
>> emkayenne wrote:
>>>
>>> Hello, I'm pretty new to R and I am having a hrd time getting a grip. Just
>>> a question: can someone tell me how to have more than one graphics windown
>>> open at the same time? I want to look at some plote at the same time...,
>>> how is this done? If someone has a suggestion for a (good) introductory
>>> guide to R, much appreciated, but not the manual..., this one I do have.
>>> :confused:
>>> Thank you for your help guys, Emkay
>>>
>>
>> --
>> View this message in context: 
>> http://www.nabble.com/Display-more-than-one-plot-tp25829214p25830526.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] Display more than one plot

2009-10-10 Thread joris meys
Hi Emkay,

If you want to look at different plots together, you can also plot
them side by side in the same plot window.

You can specify this using for example:
par(mfcol=c(2,2))
( see ?par and check mfrow and mfcol)
or
layout(matrix(1:4,2,2))
(see ?layout and ?matrix)

eg :
x <- c(1,2,3,4,5,6,7,8,9,0)
y <- c(1,2,3,4,5,6,7,8,9,0)
z <- c(8,7,6,5,4,3,2,1,0,9)

par(mfcol=c(2,2))
plot(x,y)
plot(x,z)

Kind regards
Joris

On Sat, Oct 10, 2009 at 4:51 AM, emkayenne
 wrote:
>
> Nobody? :-(
>
> emkayenne wrote:
>>
>> Hello, I'm pretty new to R and I am having a hrd time getting a grip. Just
>> a question: can someone tell me how to have more than one graphics windown
>> open at the same time? I want to look at some plote at the same time...,
>> how is this done? If someone has a suggestion for a (good) introductory
>> guide to R, much appreciated, but not the manual..., this one I do have.
>> :confused:
>> Thank you for your help guys, Emkay
>>
>
> --
> View this message in context: 
> http://www.nabble.com/Display-more-than-one-plot-tp25829214p25830526.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] Creating new variables

2009-10-10 Thread jim holtman
If the 'data set' is a dataframe, the following will work:

x$v1 <- ifelse(x$p > 0.4, 1, 0)
x$v2 <- ifelse(x$p > 0.6, 1, 0)

If it is matrix, try

x <- cbind(x, v1=ifelse(x[,'p'] > 0.4, 1, 0), v2=ifelse(x[,'p'] > 0.6, 1, 2))

If helps a lot if you follow the posting rules and  provide commented,
minimal, self-contained, reproducible code.

On Sat, Oct 10, 2009 at 6:04 PM, Ashta  wrote:
> Hi all,
>
> I have a data set called x with    200 rows  and 12  columns.  I want
> create  two more columns based on  probability. ie
>  if p >0 .4 then  v1 =1 else v1=0;
>  if p >0 .6 then  v2 =1 else v2=0;
>
> Finally x will have 14 variables.
>
> Can any one show me how to do that?
>
> Thanks
> Ashta
>
>
> .
>
>        [[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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

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


[R] Comphrensive R Function Development Documentation

2009-10-10 Thread Jason Rupert
Well, looking into the development of GUI widgets using R packages it appears 
that it is important to have well formed R functions.  Moreover, it has made me 
realize my functions are probably not well formed and should be brought closer 
inline with R standards.  

By any chance is there a single R Standards document that describes recommended 
and acceptable R functions formatting, especially for non-trival function 
inputs and outputs, e.g. mixed type inputs and outputs?  

Thank you for any guidance that can be provided.

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


[R] Creating new variables

2009-10-10 Thread Ashta
Hi all,

I have a data set called x with200 rows  and 12  columns.  I want
create  two more columns based on  probability. ie
 if p >0 .4 then  v1 =1 else v1=0;
 if p >0 .6 then  v2 =1 else v2=0;

Finally x will have 14 variables.

Can any one show me how to do that?

Thanks
Ashta


.

[[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] Running R scripts from a GUI interface

2009-10-10 Thread Liviu Andronic
On 10/10/09, Gabor Grothendieck  wrote:
> There are many approaches to GUIs in R but for something quick, which
>  I gather is your main aim here, have a look at the fgui package and
>  also the very similar ggenericwidget function in the gWidgets package.
>
There is also rpanel for building simple GUIs.
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.


[R] Nelder-Mead with output of simplex vertices

2009-10-10 Thread Ted Harding
Greetings!
I want to follow the evolution of a Nelder-Mead function
minimisation (a function of 2 variables). Hence each simplex
will have 3 vertices.

Therefore I would like to have a function which can output
the coordinates of the 3 vertices after each new simplex
is generated. However, there seems to be no way (which I can
detect) of extracting this information from optim() (the 'trace'
argument to 'control' does not seem to have provision for this,
according to '?optim', and I have tried it out without success).

I have had a good search through the R resources without finding
anything of the kind.

Of course I could write my own implementation of Nelder-Mead in R,
and generate the required output in my own way, but I would prefer
to learn that this is already been done!

Any suggestions?
With thanks,
Ted.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 10-Oct-09   Time: 22:26:16
-- XFMail --

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


Re: [R] is that possible to graph 4 dimention plot

2009-10-10 Thread Duncan Murdoch

On 07/10/2009 5:50 PM, gcheer3 wrote:

Thanks for your reply.

But I don't think it will really help. My problem is as follows:

I have 20 observations
y <- rnorm(N,mean= rep(th[1:2],N/2),sd=th[3])

I have a loglikelihood function for 3 variables mu<-(mu1,mu2) and sig
loglike <- function(mu,sig){
temp<-rep(0,length(y))
for (i in 1:(length(y)))
{
   
temp[i]<-log((1/2)*dnorm(y[i],mu[1],sig)+(1/2)*dnorm(y[i],mu[2],sig))}

return(sum(temp))
 }

for example

mu<-c(1,1.5)
sig<-2
loglike(mu,sig)

[1] -34.1811

I am interested how mu[1], mu[2], and sig changes, will effect the
loglikelihood surface. At what values of mu and sig will make loglikelihood
the maximum and at what values of mu and sig will make loglikelihood has
local max (smaller hills) and at what values of mu and sig the loglikelihood
is flat , etc. 


I tried contour3d also, seems doesn't work


I haven't seen any replies to this.  One explanation would be that 
everyone was turned off (as I was) by the rude remark above.


On this list, before saying that something "doesn't work", it's polite 
to give a simple, nicely formatted, self-contained reproducible example 
of what went wrong, and to ask whether it is your error or an error in 
the package.  Taking that approach will usually result in someone 
pointing out your error (and fixing your code); sometimes it will result 
in a package author agreeing it's a bug, and fixing it.


Duncan Murdoch



Thanks for any advice


Ryan-50 wrote:

Suppose there are 4 variables
d is a function of a , b and c
I want to know how a, b and c change will make d change
It will be straightforward to see it if we can graph the d surface

if d is only a function of a and b, I can use 'persp' to see the surface
of
d. I can easily see at what values of a and b, d will get the maxium or
minium or multiple modes, etc

But for 4 dimention graph, is there a way to show the surface of d
Will use color help

Thanks a lot
Not sure what your data looks like, but you might also 
consider looking at a 2 dimensional version.  See ?coplot

for example:

coplot(lat ~ long | depth * mag, data = quakes)

Or you can make 2 or 3-dimensional plots using the lattice 
package conditioning on some of the variables - e.g. d ~ a | b * c,
etc.  


If a, b, and c are "continuous", you can use equal.count.  Here is
an uninteresting example, considering a, b, and c as points along
a grid:

a <- b <- c <- seq(1:10)
dat <- data.frame(expand.grid(a, b, c))
names(dat) <- letters[1:3]

dat$d <- with(dat, -(a-5)^2 - (b-5)^2 - (c-5)^2)

library(lattice)
# 2-d:
xyplot(d ~ a | equal.count(b)*equal.count(c), data=dat, type="l")
# etc.

# 3-d:
contourplot(d ~ a * b | equal.count(c), data=dat)
wireframe(d ~ a * b | equal.count(c), data=dat)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] packages to download from yahoo finance

2009-10-10 Thread Dirk Eddelbuettel

On 10 October 2009 at 14:39, dinesh.som...@gatech.edu wrote:
| Hi
| 
| I am a new R user, so if this question has been raised and answered before, 
perhaps you can point me that way.
| 
| I was looking for some package/scripts that can download financial data from 
yahoo finance (or some other) website. I did check 
http://cran.r-project.org/web/packages/ but failed to find something like this. 
However, I am confident this problem has already been solved!

Yes, several times. Please see the Task View for (Empirical) Finance at
http://cran.r-project.org/web/views/Finance.html for some leads.  

It really shouldn't be too hard to answer this question, and you will need to
get into the habit of finding answers to common problems using the available
resources. 

Lastly, consider subscribing to r-sig-finance which is more topical that 
r-help. 

Dirk

-- 
Three out of two people have difficulties with fractions.

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


Re: [R] Display more than one plot

2009-10-10 Thread emkayenne

Jim, thank you for your reply. I will try that. Thanks. 
-- 
View this message in context: 
http://www.nabble.com/Display-more-than-one-plot-tp25829214p25835685.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] packages to download from yahoo finance

2009-10-10 Thread dinesh . somani
Hi

I am a new R user, so if this question has been raised and answered before, 
perhaps you can point me that way.

I was looking for some package/scripts that can download financial data from 
yahoo finance (or some other) website. I did check 
http://cran.r-project.org/web/packages/ but failed to find something like this. 
However, I am confident this problem has already been solved!

Thanks a lot.
Dinesh

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


[R] lattice auto.key drop unused levels

2009-10-10 Thread Jacob Wegelin
The following code produces a legend ("key") that mentions the unused
levels of Block.

library(MEMSS)
xyplot(yield~nitro, subset=(Block=="I" | Block=="II"), data=Oats,
group=Block, auto.key=T)

and adding "drop.unused.levels=T" does not fix it. And in fact even
the following does not solve the problem:

 xyplot(yield~nitro, data=Oats[Oats$Block=="I" | Oats$Block=="II",],
group=Block, auto.key=T)

The following workaround solves it, but seems inelegant:

junk<-Oats[Oats$Block=="I" | Oats$Block=="II",]
junk$Block<-factor(as.character(junk$Block))
xyplot(yield~nitro, group=Block, data=junk, auto.key=T)

What is the elegant or "proper R thinking" way to do this? That is, I
want to get a key that only mentions the levels of Block that are used
in the plot.

Thanks

Jacob A. Wegelin
Assistant Professor
Department of Biostatistics
Virginia Commonwealth University
730 East Broad Street Room 3006
P. O. Box 980032
Richmond VA 23298-0032
U.S.A.
E-mail: jwege...@vcu.edu
URL: http://www.people.vcu.edu/~jwegelin

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


Re: [R] Placing text in a ggplot

2009-10-10 Thread Felipe Carrillo
John:
The 'year' dataset has 366 rows, I used the 'line.count' without the '1' to 
come up with 12 rows to match the mlabs and then used line.count to draw the 
labels. Is this close to what you want?

line.count <- c(cumsum(as.vector((table(year$monthnum);line.count
namposts <- line.count;namposts
temprange <- range(year[,4], na.rm=TRUE);temprange <- max(temprange);temprange
mlabs <- month.name[1:12];mlabs

p  <- ggplot(year, aes(duration, temps, colour=month)) + geom_line() +
   ylab("Temperature (C)") + xlab("Mean Daily Temperatures")  +
   opts(legend.position = "none", title="Ottawa, 2008",
   axis.text.x = theme_blank(), axis.ticks = theme_blank()) +
   geom_vline(xintercept= line.count)

p

p +  geom_text(aes(x = namposts, y = temprange, label = mlabs),
 data = as.data.frame(line.count), colour='black', size=2.5,hjust = 1, 
vjust = 0)



Felipe D. Carrillo  
Supervisory Fishery Biologist  
Department of the Interior  
US Fish & Wildlife Service  
California, USA


--- On Fri, 10/9/09, John Kane  wrote:

> From: John Kane 
> Subject: [R] Placing text in a ggplot
> To: "R R-help" 
> Date: Friday, October 9, 2009, 12:59 PM
> I am attempting to graph 12 months of
> temperatures, delineate the months with a vline and place
> the names of the months at the top of the graph.
> 
> So far I have gotten everything to work except the names,
> despite getting a similar graph to work yesterday the day
> before yesterday with Baptise A's help.  Can anyone
> suggest what I am doing wrong.  Data set is below
> code.
> 
> Thanks.
> 
> Code 
> =
> line.count <-
> c(1,cumsum(as.vector((table(year$monthnum)
> namposts <- line.count[1:12]
> temprange <- range(year[,4], na.rm=TRUE)
> mlabs <- month.name[1:12]
> 
> p  <- ggplot(year, aes(duration, temps,
> colour=month)) + geom_line() +
>        ylab("Temperature (C)") +
> xlab("Mean Daily Temperatures")  +
>        opts(legend.position =
> "none", title="Ottawa, 2008",
>        axis.text.x =
> theme_blank(), axis.ticks = theme_blank()) +
>        geom_vline(xintercept=
> line.count) 
> 
> [[elided Yahoo spam]]
>        
> p +  geom_text(aes(x = namposts, y = temprange[2],
> label = mlabs),
>      data = year, size = 2.5,
> colour='black', hjust = 0, vjust = 0)
> 
> ==
> 
> year  <- structure(list(monthnum = c(1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 
> 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> 2L, 
> 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> 2L, 
> 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
> 3L, 
> 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
> 3L, 
> 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
> 4L, 
> 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
> 4L, 
> 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
> 5L, 
> 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
> 6L, 
> 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
> 6L, 
> 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L,
> 7L, 
> 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
> 7L, 
> 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L,
> 8L, 
> 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
> 8L, 
> 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L,
> 9L, 
> 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
> 9L, 
> 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L,
> 10L, 
> 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
> 10L, 
> 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
> 10L, 
> 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
> 11L, 
> 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
> 11L, 
> 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
> 12L, 
> 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
> 12L, 
> 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L), days = c(1L,
> 2L, 
> 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
> 16L, 
> 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L,
> 29L, 
> 30L, 31L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
> 12L, 
> 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
> 25L, 
> 26L, 27L, 28L, 29L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
> 10L, 
> 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L,
> 23L, 
> 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 1L, 2L, 3L, 4L, 5L,
> 6L, 
> 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
> 19L, 
> 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 1L,
> 2L, 
> 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
> 16L, 
> 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L,
> 29L, 
> 30L, 31L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
> 12L, 
> 13L, 14L, 15L, 16L, 17L, 18L,

Re: [R] odfWeave & XML error in post-processing

2009-10-10 Thread Max Kuhn
There is a function called odfTranslate that will help deal with  
characters that might confound XML. You might need to use it on the  
row/column names of your output.


Max

On Oct 10, 2009, at 11:33 AM, Rob James  wrote:

Just to close out my earlier posting, I have identified and resolved  
the following odfWeave/XML error:



xmlParseStartTag: invalid element name



I  used odfWeave to call various logistic regression models which  
included the above mentioned variable. odfWeave failed to generate  
the destination file throwing multiple lines of the above error.


It happened that the dataset originated in STATA (probably  
irrelevant),  and included a variable which had five levels. Two of  
those levels had values of

"(1)<3500" and "(5)=>5000".
So, while these codes did not appear in the source document, these  
codes appear in the odfWeave destination file.   The results were  
displayed in the document using the following crude method:


results <-glm(..

and subsequently reported out using :

odfTable(

as.matrix(results[,c(X1, X2, X3)],)

horizontal = TRUE)

odfTableCaption("Selected Logistic Regression Results for RXN3  
outcome")



@

I received xmlParseStartTag errors for each such table.  Editting of  
the XML file in gedit highlighted the above values as problematic.


I then removed the two problematic value for this variable, and re- 
ran odfWeave, which generated the output I needed.


So, it appears that these values of this variable operated as  
invalid xmlParseStartTags, and that the process of wrapping up  
content_1.xml back into an ODF file failed because of the mis- 
recognition of these ParseStartTags found embedded in the data.   I  
think this is likely to be regarded more as a feature than as a bug,  
but it is none-the-less a cautionary tale.


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

2009-10-10 Thread Eiger

Hi, I have a question about "how" write output in a .txt file.

With tihs command, I write permutations of the numbers (1,2,3) in a .txt
file:

> x<-permn(c(1,2,3))
> write.table(x, file="filename.txt", row.names=F, col.names=F)

This is output in filename.txt:

1 1 3 3 2 2
2 3 1 2 3 1
3 2 2 1 1 3

Is possible write output trasposed?
Output:



etc..

Is possible write output in a single column?
Output:
1
2
3
1
3
2
3
1
2
etc. etc.
_

Thanks,
E.



-- 
View this message in context: 
http://www.nabble.com/permutations-tp25834463p25836847.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] Tabulation

2009-10-10 Thread Charles C. Berry

On Sat, 10 Oct 2009, Dieter Menne wrote:





Ashta wrote:



I have a data set
x1  x2 x3
 1   2   1
 1   2   3
 2   1   2
 1   2   1
 3   1   1

 I want to tabulate in the following way.
1   2   3
 x13   2   1
 x22   3   0
 x33   1   1

It is just like frequency distribution



See function table.



and colnames() and col()

If your data are in a matrix or data.frame called 'dat'


table(colnames(dat)[col(dat)], unlist(dat))


 1 2 3
  x1 3 1 1
  x2 2 3 0
  x3 3 1 1




HTH,

Chuck



Dieter

--
View this message in context: 
http://www.nabble.com/Tabulation-tp25834839p25835126.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.



Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

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

2009-10-10 Thread Orvalho Augusto
Hello guys I am new to this list and for R too.

I am wondering if there is a patch for the SPSS reading code on the
foreign package, in order to be able to read long variable names.
Right now read.spss() just trunc the names to 8 characters.

Or if someone could help me on other way:
I have to process everyday a lot of SPSS Syntax Files and Dat files
that come from one system that can only export data on through that
way.

I use PSPP to generate the spss data file (sav) that I read with R.
>From R I can export to MySQL, DBF and STATA to satisfy the needs of
different guys here.

The problem is the limit of 8 characters long on variable names.

Can someone help on that?

Caveman

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


Re: [R] user input in R

2009-10-10 Thread Robert Baer

I'm just learning R (I don't know any other programming languages),
  and I have a question. I am trying to figure out how to ask for user
  input (say, a set of 3 numbers) then put those numbers into an array.
  I've looked around, but I haven't been able to find any answers that I
  understand.
  Thanks!


Astoundingly, finding out how to load my own datasets was one of the hardest 
things for me to find information on when I was new to R and I had 
considerable programming experience.  Part of the problem was that I didn't 
yet know exactly what R documentation was available or how to easily access 
it.  Further, veteran users tend to assume loading datasets is easy, and 
much documentation and sample code uses 'generated data'.  Thus, sample code 
demonstrating 'loading datasets' is a little hard to find when you are 
starting out!


The official recommendation would go something like, "You probably want to 
read the Import/Export documentation."You can find this on Windows GUI 
under help | manuals | Data Import/Export.  Of course you proably also need 
to read chapter 7 of An Introduction to R which is also linked under manuals 
in the help menu.  That said, I offer some beginner cheats you might find 
useful below.  I particularly recommend the Verzzani Appendix.


Things you could type at the command line to learn more about different ways 
to enter data are:

?scan
?read.table
?read.delim
?read.csv

"Beginner cheats Suggestions"

If you want GUI data input (of dataframes), I'd suggest installing and 
running the Rcmdr package.  It lets you load many types of datasets, 
including Excel files.  These can be used within Rcmdr or from the command 
line.


If you are really new to R, I suggest looking at some of the contributed 
documentation to get a feel for how things are done as well as how to load 
user data

http://cran.us.r-project.org/other-docs.html

In particular, look at the appendix in John Verzzani's document to see a 
pragmatic description of using scan to input user data.  (see Appendix: 
Entering Data in R on p. 103 or so).

http://cran.us.r-project.org/doc/contrib/Verzani-SimpleR.pdf

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


Re: [R] permutations

2009-10-10 Thread Eiger


Dirk Eddelbuettel wrote:
> 
> Supply an argument 'lib' pointing to a directory where you write to, or
> alternatively (but not generally recommended) run R as root to install the
> package as root can write to /usr/lib/R/lib.
> 
> Dirk
> 

OK!  I've installed this package.
Thank you!
:)

Example:

> permn((c(23,45,56)))

[[1]]
[1] 23 45 56

[[2]]
[1] 23 56 45

[[3]]
[1] 56 23 45

[[4]]
[1] 56 45 23

[[5]]
[1] 45 56 23

[[6]]
[1] 45 23 56

-- 
View this message in context: 
http://www.nabble.com/permutations-tp25834463p25835454.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] permutations

2009-10-10 Thread Eiger


Eiger wrote:
> 
> 
> When I try to install the "combinat" package, it give me these errors:
> _
> 
> Error in utils::install.packages(l[s + 1]) : unable to install packages
> _
> 
> What can I do?
> 

(I use Linux Mandriva 2008 Spring)

-- 
View this message in context: 
http://www.nabble.com/permutations-tp25834463p25835290.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] Tabulation

2009-10-10 Thread Gabor Grothendieck
Here are a couple of possibilities both based on first converting the
data frame to long form:

> xtabs(~ind + values, stack(DF))
values
ind  1 2 3
  x1 3 1 1
  x2 2 3 0
  x3 3 1 1
> t(table(stack(DF)))
values
ind  1 2 3
  x1 3 1 1
  x2 2 3 0
  x3 3 1 1


On Sat, Oct 10, 2009 at 10:43 AM, Ashta  wrote:
> Hi all,
>
> I have a data set
> x1  x2 x3
>  1   2   1
>  1   2   3
>  2   1   2
>  1   2   1
>  3   1   1
>
>  I want to tabulate in the following way.
>        1   2   3
>  x1    3   2   1
>  x2    2   3   0
>  x3    3   1   1
>
> It is just like frequency distribution
>
>
> Any help is highly appreciated
>
>        [[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] permutations

2009-10-10 Thread Dirk Eddelbuettel

On 10 October 2009 at 08:15, Eiger wrote:
| require(combinat)
| permn((c(23,46,70,71,89))
| 
| Thanks.
| When I try to install the "combinat" package, it give me these errors:
| _
| --- Please select a CRAN mirror for use in this session ---
| Warning in utils::install.packages(l[s + 1]) :
|   argument 'lib' is missing: using '/usr/lib/R/lib'
| Warning in utils::install.packages(l[s + 1]) :
|   'lib = "/usr/lib/R/lib"' is not writable
| Error in utils::install.packages(l[s + 1]) : unable to install packages
| _
| 
| What can I do?

Supply an argument 'lib' pointing to a directory where you write to, or
alternatively (but not generally recommended) run R as root to install the
package as root can write to /usr/lib/R/lib.

Dirk

-- 
Three out of two people have difficulties with fractions.

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


Re: [R] odfWeave & XML error in post-processing

2009-10-10 Thread Rob James
Just to close out my earlier posting, I have identified and resolved the 
following odfWeave/XML error:



xmlParseStartTag: invalid element name



I  used odfWeave to call various logistic regression models which 
included the above mentioned variable. odfWeave failed to generate the 
destination file throwing multiple lines of the above error.


It happened that the dataset originated in STATA (probably irrelevant),  
and included a variable which had five levels. Two of those levels had 
values of
"(1)<3500" and "(5)=>5000".   

So, while these codes did not appear in the source document, these codes 
appear in the odfWeave destination file.   The results were displayed in 
the document using the following crude method:


results <-glm(..

and subsequently reported out using :

odfTable(

as.matrix(results[,c(X1, X2, X3)],)

horizontal = TRUE)

odfTableCaption("Selected Logistic Regression Results for RXN3 outcome")


@

I received xmlParseStartTag errors for each such table.  Editting of the 
XML file in gedit highlighted the above values as problematic.


I then removed the two problematic value for this variable, and re-ran 
odfWeave, which generated the output I needed.


So, it appears that these values of this variable operated as invalid 
xmlParseStartTags, and that the process of wrapping up content_1.xml 
back into an ODF file failed because of the mis-recognition of these 
ParseStartTags found embedded in the data.   I think this is likely to 
be regarded more as a feature than as a bug, but it is none-the-less a 
cautionary tale.


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


Re: [R] easy way to find all extractor functions and the datatypes of what they return

2009-10-10 Thread David Winsemius
Building on the two prior suggestions ( str() and methods() )  you  
could write a function to get both the named components of an object  
and the functions that work on its class. Using the example lm.D9 in  
the help page for lm:


get_mths_str <- function(obj) c(functs =  
list(methods(class=class(obj))),

components=list(names(lm.D9))
   )

> get_mths_str(lm.D9)
$functs
 [1] add1.lm*   addterm.lm*alias.lm*   
anova.lm   attrassign.lm*
 [6] boxcox.lm* case.names.lm* confint.lm* 
cooks.distance.lm* deviance.lm*
[11] dfbeta.lm* dfbetas.lm*drop1.lm*   
dropterm.lm*   dummy.coef.lm*
[16] effects.lm*extractAIC.lm* family.lm*  
formula.lm*hatvalues.lm
[21] influence.lm*  kappa.lm   labels.lm*  
logLik.lm* logtrans.lm*
[26] model.frame.lm model.matrix.lmplot.lm 
predict.lm print.lm
[31] proj.lm*   residuals.lm   rstandard.lm
rstudent.lmsimulate.lm*

[36] summary.lm variable.names.lm* vcov.lm*

   Non-visible functions are asterisked

$components
 [1] "coefficients"  "residuals" "effects"   "rank"   
"fitted.values" "assign"
 [7] "qr""df.residual"   "contrasts" "xlevels"
"call"  "terms"

[13] "model"

--
David

On Oct 10, 2009, at 8:43 AM, Gabor Grothendieck wrote:


Try this (where "lm" is the class of the lm output):


methods(class = "lm")
[1] add1.lm*   alias.lm*  anova.lm
case.names.lm*
[5] confint.lm*cooks.distance.lm* deviance.lm*
dfbeta.lm*
[9] dfbetas.lm*drop1.lm*  dummy.coef.lm*  
effects.lm*
[13] extractAIC.lm* family.lm* formula.lm* 
hatvalues.lm
[17] influence.lm*  kappa.lm   labels.lm*  
logLik.lm*
[21] model.frame.lm model.matrix.lmplot.lm 
predict.lm
[25] print.lm   proj.lm*   residuals.lm
rstandard.lm
[29] rstudent.lmsimulate.lm*   summary.lm  
variable.names.lm*

[33] vcov.lm*

  Non-visible functions are asterisked


On Sat, Oct 10, 2009 at 3:21 AM, Robert Wilkins   
wrote:

Am I asking for too much:
for any object that a stat proc returns  ( y <- lm( y~x) ,  
etc ) ) , is there
a super convenient function like give_all_extractors( y ) that  
lists all

extractor functions , the datatype returned , and a text descriptor
field ("pairwisepval" "lsmean" etc)

That would just be so convenient.

What are my options for querying an object so that I can quickly  
learn

the extractor functions to pull out the data and manipulate it?
Will the datatypes returned usually be named vectors and named
matrices, indiced by categorical values in the data
( "Male" "Female"  "Placebo" "DrugB" etc )? If they are indexed by  
1 ,

2 , 3 , 4 , it's easier to lose track.

thanks a bunch in advance

--




David Winsemius, MD
Heritage Laboratories
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] Tabulation

2009-10-10 Thread Dieter Menne



Ashta wrote:
> 
> 
> I have a data set
> x1  x2 x3
>  1   2   1
>  1   2   3
>  2   1   2
>  1   2   1
>  3   1   1
> 
>  I want to tabulate in the following way.
> 1   2   3
>  x13   2   1
>  x22   3   0
>  x33   1   1
> 
> It is just like frequency distribution
> 

See function table.

Dieter

-- 
View this message in context: 
http://www.nabble.com/Tabulation-tp25834839p25835126.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] permutations

2009-10-10 Thread Eiger


require(combinat)
permn((c(23,46,70,71,89))

Thanks.
When I try to install the "combinat" package, it give me these errors:
_
--- Please select a CRAN mirror for use in this session ---
Warning in utils::install.packages(l[s + 1]) :
  argument 'lib' is missing: using '/usr/lib/R/lib'
Warning in utils::install.packages(l[s + 1]) :
  'lib = "/usr/lib/R/lib"' is not writable
Error in utils::install.packages(l[s + 1]) : unable to install packages
_

What can I do?
-- 
View this message in context: 
http://www.nabble.com/permutations-tp25834463p25835092.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] Text Mining in R

2009-10-10 Thread Axel Urbiz
Dear R users,

I'm new in Text Mining applications and just started to look into the tm
package. If anyone of you has experience with this package, I'll appreciate
if you could share your thoughts around it. Also what's the best way to
store large amounts of text data on limited RAM when using this package.

Thanks in advance for your help

Axel.

[[alternative HTML version deleted]]

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


Re: [R] permutations

2009-10-10 Thread David Winsemius

require(combinat)
permn((c(23,46,70,71,89))

On Oct 10, 2009, at 10:05 AM, Eiger wrote:



Question 1.
I would calculate all the permutations of numbers (23,46,70,71,89)
How can I write correctly the code?

(Load gregmisc)


permutations (..?...)

__

Question 2.
It's possible permute a string?
..for example:
EIGER
EGIER
EREGI
etc..etc..

Thanks,
E.
--
View this message in context: 
http://www.nabble.com/permutations-tp25834463p25834463.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.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


[R] Tabulation

2009-10-10 Thread Ashta
Hi all,

I have a data set
x1  x2 x3
 1   2   1
 1   2   3
 2   1   2
 1   2   1
 3   1   1

 I want to tabulate in the following way.
1   2   3
 x13   2   1
 x22   3   0
 x33   1   1

It is just like frequency distribution


Any help is highly appreciated

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

2009-10-10 Thread Eiger

Question 1.
I would calculate all the permutations of numbers (23,46,70,71,89)
How can I write correctly the code?

(Load gregmisc)

> permutations (..?...)
__

Question 2.
It's possible permute a string?
..for example:
EIGER
EGIER
EREGI
etc..etc..

Thanks,
E.
-- 
View this message in context: 
http://www.nabble.com/permutations-tp25834463p25834463.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] Running R scripts from a GUI interface

2009-10-10 Thread Gabor Grothendieck
There are many approaches to GUIs in R but for something quick, which
I gather is your main aim here, have a look at the fgui package and
also the very similar ggenericwidget function in the gWidgets package.

On Sat, Oct 10, 2009 at 1:05 AM, Jason Rupert  wrote:
> It appears several that of my scripts are beginning to reaching maturity, so 
> I am curious if it is possible to add an external GUI to run the scripts from 
> this simplified GUI interface.
>
> The scripts are fairly rudimentary so the GUI only needs a few radial buttons 
> and a could of numeric fields.
>
> I am curious if there is a typical approach for developing a GUI to run R 
> scripts or to export R scripts in a DLL or other format so that they can be 
> run from such a GUI.
>
> I also have not settled on a GUI development language so any suggestions 
> there are also very much appreciated.
>
> Thank you again for any feedback and insights, especially if there is a blog 
> or book that covers these topics.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Creating a Clustered-Stacked Column Chart

2009-10-10 Thread Peter Ehlers

I think you're missing the point. David _did_ show you how
to create a graph showing 4 clusters of stacked barcharts.
If you want them side-by-side instead of in the matrix
layout David gave, use the layout= argument.

 -Peter Ehlers

zhijie zhang wrote:

Hi David,
  Your codes are for stacked chart. Actually, i hope to Create a
Clustered-Stacked Column Chart, which means that a chart will combine the
traits of stacked chart and clustered chart, see the example in the page
http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html.
  Thanks.
2009/10/10 David Winsemius 


library(lattice)
barchart(Titanic, scales = list(x = "free"),
 auto.key = list(title = "Survived"))

Or if you prefer vertical:

barchart(Titanic, scales = list(x = "free"),
auto.key = list(title = "Survived"), horizontal=FALSE)

There are adjustments available to the space between bars.

barchart(Titanic, scales = list(x = "free"),
auto.key = list(title = "Survived"), horizontal=FALSE,
box.ratio=100)



On Oct 9, 2009, at 9:57 PM, zhijie zhang wrote:

  Thanks a lot. Maybe someone else has the method to solve that.


2009/10/9 John Kane 

  I don't think I've seen an R version, probably because the technique is

not
very good for displaying data.

Have a look at http://chartsgraphs.wordpress.com/tag/r-and-excel/ for an
alternative method of displaying the data using lattice.

--- On Fri, 10/9/09, zhijie zhang  wrote:

From: zhijie zhang 

Subject: [R] Creating a Clustered-Stacked Column Chart
To: r-h...@stat.math.ethz.ch
Received: Friday, October 9, 2009, 5:31 AM
Hi all,
 In R, is there some functions or ways to
create a Clustered-Stacked
Column Chart as the example in the following page
http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html?
 I have browsed the R Graph Gallery (


http://addictedtor.free.fr/graphiques/)


and searched the R site, and didnot find an appropriate
method to do it.
 Anybody has met this problem before?
 Thanks a lot.

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



   __
Get the name you've always wanted @ymail.com or @rocketmail.com! Go to
http://ca.promos.yahoo.com/jacko/



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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT




[[alternative HTML version deleted]]

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




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


Re: [R] Creating a Clustered-Stacked Column Chart

2009-10-10 Thread David Winsemius
I gave you more than you deserved. You provided no data and a link to  
what appeared to me to be a rather ugly looking chart. I gave you the  
help examples from the lattice equivalent. The barchart (stacked  
column chart in your termnology) is "clustered" although it happens to  
be presented in an informative display rather than an uninformative one.


(Suggest you read the Posting Guide.)

--
David
On Oct 10, 2009, at 7:53 AM, zhijie zhang wrote:


Hi David,
  Your codes are for stacked chart. Actually, i hope to Create a  
Clustered-Stacked Column Chart, which means that a chart will  
combine the traits of stacked chart and clustered chart, see the  
example in the page http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html 
.

  Thanks.
2009/10/10 David Winsemius 
library(lattice)
barchart(Titanic, scales = list(x = "free"),
 auto.key = list(title = "Survived"))

Or if you prefer vertical:

barchart(Titanic, scales = list(x = "free"),
auto.key = list(title = "Survived"), horizontal=FALSE)

There are adjustments available to the space between bars.

barchart(Titanic, scales = list(x = "free"),
auto.key = list(title = "Survived"), horizontal=FALSE,  
box.ratio=100)




On Oct 9, 2009, at 9:57 PM, zhijie zhang wrote:

Thanks a lot. Maybe someone else has the method to solve that.


2009/10/9 John Kane 

I don't think I've seen an R version, probably because the technique  
is not

very good for displaying data.

Have a look at http://chartsgraphs.wordpress.com/tag/r-and-excel/  
for an

alternative method of displaying the data using lattice.

--- On Fri, 10/9/09, zhijie zhang  wrote:

From: zhijie zhang 
Subject: [R] Creating a Clustered-Stacked Column Chart
To: r-h...@stat.math.ethz.ch
Received: Friday, October 9, 2009, 5:31 AM
Hi all,
 In R, is there some functions or ways to
create a Clustered-Stacked
Column Chart as the example in the following page
http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html?
 I have browsed the R Graph Gallery (
http://addictedtor.free.fr/graphiques/)
and searched the R site, and didnot find an appropriate
method to do it.
 Anybody has met this problem before?
 Thanks a lot.

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



   __
Get the name you've always wanted @ymail.com or @rocketmail.com! Go to
http://ca.promos.yahoo.com/jacko/


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

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




David Winsemius, MD
Heritage Laboratories
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] easy way to find all extractor functions and the datatypes of what they return

2009-10-10 Thread Gabor Grothendieck
Try this (where "lm" is the class of the lm output):

> methods(class = "lm")
 [1] add1.lm*   alias.lm*  anova.lm   case.names.lm*
 [5] confint.lm*cooks.distance.lm* deviance.lm*   dfbeta.lm*
 [9] dfbetas.lm*drop1.lm*  dummy.coef.lm* effects.lm*
[13] extractAIC.lm* family.lm* formula.lm*hatvalues.lm
[17] influence.lm*  kappa.lm   labels.lm* logLik.lm*
[21] model.frame.lm model.matrix.lmplot.lmpredict.lm
[25] print.lm   proj.lm*   residuals.lm   rstandard.lm
[29] rstudent.lmsimulate.lm*   summary.lm variable.names.lm*
[33] vcov.lm*

   Non-visible functions are asterisked


On Sat, Oct 10, 2009 at 3:21 AM, Robert Wilkins  wrote:
> Am I asking for too much:
> for any object that a stat proc returns  ( y <- lm( y~x) , etc ) ) , is there
> a super convenient function like give_all_extractors( y ) that lists all
> extractor functions , the datatype returned , and a text descriptor
> field ("pairwisepval" "lsmean" etc)
>
> That would just be so convenient.
>
> What are my options for querying an object so that I can quickly learn
> the extractor functions to pull out the data and manipulate it?
> Will the datatypes returned usually be named vectors and named
> matrices, indiced by categorical values in the data
> ( "Male" "Female"  "Placebo" "DrugB" etc )? If they are indexed by 1 ,
> 2 , 3 , 4 , it's easier to lose track.
>
> thanks a bunch in advance
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] easy way to find all extractor functions and the datatypes of what they return

2009-10-10 Thread Peter Ehlers



Robert Wilkins wrote:

Am I asking for too much:
for any object that a stat proc returns  ( y <- lm( y~x) , etc ) ) , is there
a super convenient function like give_all_extractors( y ) that lists all
extractor functions , the datatype returned , and a text descriptor
field ("pairwisepval" "lsmean" etc)


I think that you _are_ asing for too much. (But that's not to
say that you shouldn't consider providing code for such a
function yourself.)



That would just be so convenient.

What are my options for querying an object so that I can quickly learn
the extractor functions to pull out the data and manipulate it?
Will the datatypes returned usually be named vectors and named
matrices, indiced by categorical values in the data
( "Male" "Female"  "Placebo" "DrugB" etc )? If they are indexed by 1 ,
2 , 3 , 4 , it's easier to lose track.


The way to learn about extractor functions is to read the help
pages which you would surely do before using any function that
you haven't used previously. ?lm, for example, would point you
to coef, effects, residuals, fitted, vcov. (Be aware, however,
that not all contributed packages provide help of the same
calibre as does base R.)

The other, highly recommended, way to learn about objects in R
is the str() function. Use it often.

As to your question about named objects, R is almost obsessive
about preserving names.

 -Peter Ehlers



thanks a bunch in advance

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Matching Dates Closest without going over

2009-10-10 Thread Gabor Grothendieck
Create two zoo series, merge them and use na.locf (last occurence
carried forward):
library(zoo)

z1 <- zoo(as.numeric(d1), d1)
z2 <- zoo(as.numeric(d2), d2)
z <- merge(z1, z2)

z.na.locf <- na.locf(z, na.rm = FALSE)[time(z1)]

transform(as.data.frame(z.na.locf), z1 = as.Date(z1), z2 = as.Date(z2))


# Note that if the real situation is that you have two input zoo
series, z1 and z2,
# that you wish to merge then its really only this:

na.locf(merge(z1, z2), na.rm = FALSE)[time(z1)]


See the help files for merge.zoo, na.locf.zoo and the three zoo
vignettes for more.


On Sat, Oct 10, 2009 at 12:14 AM, ampc  wrote:
>
> Hi,
>
> I have 2 date vectors d1 and d2.
>
> d1 <- structure(c(14526, 14495, 14464, 14433, 14402, 14371, 14340, 14309,
> 14278, 14247, 14216, 14185), class = "Date")
> d2 <- structure(c(14526, 14509, 14488, 14466, 14453, 14441, 14396, 14388,
> 14343, 14333, 14310, 14281), class = "Date")
>
> I would like to create another dataframe with columns d1 and d2, where d1 is
> the original d1 and d2 is the max(d2) such that d1 > d2. And NA's where not
> applicable.
> (See desired result below)
>
> Thanks,
> Ampy
>
>
>
> d1
> 2009-10-09
> 2009-09-08
> 2009-08-08
> 2009-07-08
> 2009-06-07
> 2009-05-07
> 2009-04-06
> 2009-03-06
> 2009-02-03
> 2009-01-03
> 2008-12-03
> 2008-11-02
>
>
> d2
> 2009-10-09
> 2009-09-22
> 2009-09-01
> 2009-08-10
> 2009-07-28
> 2009-07-16
> 2009-06-01
> 2009-05-24
> 2009-04-09
> 2009-03-30
> 2009-03-07
> 2009-02-06
>
> result:
>
> d1                         d2
> 2009-10-09           2009-10-09
> 2009-09-08           2009-09-01
> 2009-08-08           2009-07-28
> 2009-07-08           2009-06-01
> 2009-06-07           2009-06-01
> 2009-05-07           2009-04-09
> 2009-04-06           2009-03-30
> 2009-03-06           2009-02-06
> 2009-02-03           NA
> 2009-01-03           NA
> 2008-12-03           NA
> 2008-11-02           NA
>
> --
> View this message in context: 
> http://www.nabble.com/Matching-Dates-Closest-without-going-over-tp25830902p25830902.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] Running R scripts from a GUI interface

2009-10-10 Thread Barry Rowlingson
On Sat, Oct 10, 2009 at 1:01 PM, Jason Rupert  wrote:
> Thank you very much for your response and it looks like R Commander is very 
> capable, but I think it is heading the wrong direction from where we are 
> looking to go, i.e. simpler interface.
>
> I guess (and I may be dating myself) when I was previously working with 
> MATLAB I could use something like Real-time Workshop and EmbeddedCoder to 
> export a C/C++ code of all our scripts that could be built into a DLL.  I 
> would then use VisualBasic (I would like to use TCL/TK or other more current 
> language) to create a very basic GUI that just had four radials and one text 
> entry field and load in the DLL.  It would not have all commandline and all 
> the other unnecessary bits, especially since the script reached maturity and 
> would not need to be altered.
>

There is a tcltk package for R that lets you build guis, or you could
write your application in Python, use PyQt4 to build your gui (which
comes with a graphical gui designer) and Rpy to communicate between
Python and R.

 There's some other suggestions in the Graphics Task View:
http://ftp.heanet.ie/mirrors/cran.r-project.org/web/views/Graphics.html

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] Running R scripts from a GUI interface

2009-10-10 Thread Jason Rupert
Thank you very much for your response and it looks like R Commander is very 
capable, but I think it is heading the wrong direction from where we are 
looking to go, i.e. simpler interface.   

I guess (and I may be dating myself) when I was previously working with MATLAB 
I could use something like Real-time Workshop and EmbeddedCoder to export a 
C/C++ code of all our scripts that could be built into a DLL.  I would then use 
VisualBasic (I would like to use TCL/TK or other more current language) to 
create a very basic GUI that just had four radials and one text entry field and 
load in the DLL.  It would not have all commandline and all the other 
unnecessary bits, especially since the script reached maturity and would not 
need to be altered.  

I'm curious if R allows something like things, i.e. to further simply so that a 
simple GUI and DLL of the scripts could be delivered.

Thanks again for any insights and feedback you can provide. 




--- On Sat, 10/10/09, glen_b  wrote:

> From: glen_b 
> Subject: Re: [R] Running R scripts from a GUI interface
> To: r-help@r-project.org
> Date: Saturday, October 10, 2009, 2:12 AM
> 
> 
> 
> Jason Rupert wrote:
> > 
> > I am curious if there is a typical approach for
> developing a GUI to run R
> > scripts or to export R scripts in a DLL or other
> format so that they can
> > be run from such a GUI. 
> > 
> > I also have not settled on a GUI development language
> so any suggestions
> > there are also very much appreciated.  
> > 
> 
> R Commander http://cran.r-project.org/web/packages/Rcmdr/index.html
> is a basic stats GUI in R that provides a way for others to
> make a simple 
> GUI interface to a package. Many R packages have GUI
> versions that work 
> with R Commander.
> 
> It would seem to be a fairly simple way to do it. 
> 
> -- 
> View this message in context: 
> http://www.nabble.com/Running-R-scripts-from-a-GUI-interface-tp25831129p25831651.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] Creating a Clustered-Stacked Column Chart

2009-10-10 Thread zhijie zhang
Hi David,
  Your codes are for stacked chart. Actually, i hope to Create a
Clustered-Stacked Column Chart, which means that a chart will combine the
traits of stacked chart and clustered chart, see the example in the page
http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html.
  Thanks.
2009/10/10 David Winsemius 

> library(lattice)
> barchart(Titanic, scales = list(x = "free"),
>  auto.key = list(title = "Survived"))
>
> Or if you prefer vertical:
>
> barchart(Titanic, scales = list(x = "free"),
> auto.key = list(title = "Survived"), horizontal=FALSE)
>
> There are adjustments available to the space between bars.
>
> barchart(Titanic, scales = list(x = "free"),
> auto.key = list(title = "Survived"), horizontal=FALSE,
> box.ratio=100)
>
>
>
> On Oct 9, 2009, at 9:57 PM, zhijie zhang wrote:
>
>   Thanks a lot. Maybe someone else has the method to solve that.
>>
>>
>> 2009/10/9 John Kane 
>>
>>   I don't think I've seen an R version, probably because the technique is
>>> not
>>> very good for displaying data.
>>>
>>> Have a look at http://chartsgraphs.wordpress.com/tag/r-and-excel/ for an
>>> alternative method of displaying the data using lattice.
>>>
>>> --- On Fri, 10/9/09, zhijie zhang  wrote:
>>>
>>> From: zhijie zhang 
 Subject: [R] Creating a Clustered-Stacked Column Chart
 To: r-h...@stat.math.ethz.ch
 Received: Friday, October 9, 2009, 5:31 AM
 Hi all,
  In R, is there some functions or ways to
 create a Clustered-Stacked
 Column Chart as the example in the following page
 http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html?
  I have browsed the R Graph Gallery (

>>> http://addictedtor.free.fr/graphiques/)
>>>
 and searched the R site, and didnot find an appropriate
 method to do it.
  Anybody has met this problem before?
  Thanks a lot.

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


>>>
>>>__
>>> Get the name you've always wanted @ymail.com or @rocketmail.com! Go to
>>> http://ca.promos.yahoo.com/jacko/
>>>
>>>
>>[[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.
>>
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
>

[[alternative HTML version deleted]]

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


Re: [R] variance ratio tests

2009-10-10 Thread Peter Ehlers



amira akl wrote:

Hello
I am a new user of R software. I benefit from using vrtest-package. However, the codes provided by the aforementioned package, for example, calculate the test statistics for Lo and Mackinlay (1988) under the assumptions of homoscedasticity and heteroscedasticity without computing the value of the variance ratio itself. 
 
I would be grateful if you could instruct me how to calculate the variance ratio of Lo and Mackinlay (1988) and Chow and Denning (1993)


You could look at the code; looks pretty simple to me.
It seems that both Lo.Mac and Chow.Denning call LM_stat()
which you can see with

 vrtest:::LM_stat

 -Peter Ehlers

 
 
Waiting eagerly for your reply.

Amira Akl Ahmed


  
	[[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] Setting a mirror "permanently" on R on ubuntu

2009-10-10 Thread Bernardo Rangel Tura
On Sat, 2009-10-10 at 04:54 +0100, Lazarus Mramba wrote:
> Dear all,
> 
> I seem to have many problems as I run R on my ubuntu system.
> want to set a mirror so that anytime I use the command "install.packages",
> it does not ask me for which mirror to use but go direct.
> This is because of the error I keep on getting below and I dont know how to
> solve it.
> 
> Please help.
> 
> Kind regards,
> Lazarus


Lazarus,

use options(repos="mirror URL")

-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil

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


Re: [R] auto.key legend color different from actual plot

2009-10-10 Thread Deepayan Sarkar
On Sat, Oct 10, 2009 at 12:13 AM, Rene  wrote:
> Dear All,
>
>
>
> I have created a barchart, but the legend created by auto.key does not match
> the actual graph. Can someone give me some hint here?
>
>
>
> For example, my coding are:
>
>
>
> Library(lattice)
>
> dataset.table <-
> table(data.frame(id=c("a","b","c","a","c","b","a"),colour=c("blue","green","
> red","red","red","green","green")))
>
> blue<-hcl(238,60,100)
>
> green<-hcl(120,70,100)
>
> violet<-hcl(350,100,100)
>
> barchart(rbind(dataset.table),horizontal =
> FALSE,col=c(blue,green,violet),stack=FALSE, auto.key=TRUE)
>
>
>
>
>
> As you can see, the actual plot, the color is blue, green then violet, but
> in the legend, it is blue, violet and green. Can someone help me correct the
> legend colour?

See

?simpleTheme

-Deepayan

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


Re: [R] subsetting key on qqmath

2009-10-10 Thread Deepayan Sarkar
On Thu, Oct 8, 2009 at 8:11 PM, John Field  wrote:
> Dear R list,
>
> The code below puts qq-plots for two of three groups on the one plot.
>  However the legend includes all three groups, ie the auto.key ignores the
> subset instruction.  Is there an easy way to get around this, so that only
> those groups plotted are included in the legend?
>
> y1<-rnorm(100); y2<-rnorm(100)+1; y3<-rnorm(100)+2; y<-c(y1,y2,y3)
> fact=factor(c(rep(1,100),rep(2,100),rep(3,100)))
> require(lattice)
> qqmath(~y,groups=fact,auto.key=list(corner=c(0,1)),subset=fact!=2)

The subsetting of groups happens independently in each panel. As
there's no guarantee in general that the subset will have the same
non-empty set of levels in each panel, the only solution (with a
common legend) is to keep all the levels.

To drop unused levels in groups, you need to subset your data
beforehand. For example,

df <- data.frame(y=c(y1,y2,y3),
fact=factor(c(rep(1,100),rep(2,100),rep(3,100
qqmath(~y, data=subset(df, fact!=2),
groups=fact[drop=TRUE],auto.key=list(corner=c(0,1)))

-Deepayan

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


Re: [R] svy / weighted regression

2009-10-10 Thread Peter Dalgaard

Sorry, forgot to "reply all"...

Laust wrote:

Dear list,

I am trying to set up a propensity-weighted regression using the
survey package. Most of my population is sampled with a sampling
probability of one (that is, I have the full population). However, for
a subset of the data I have only a 50% sample of the full population.
In previous work on the data, I analyzed these data using SAS and
STATA. In those packages I used a propensity weight of 1/[sampling
probability] in various generalized linear regression-procedures, but
I am having trouble setting this up. I bet the solution is simple, but
I’m a R newbie. Code to illustrate my problem below.


Hi Laust,

You probably need the package author to explain fully, but as far as I
can see, the crux is that a dispersion parameter is being used, based on
Pearson residuals, even in the Poisson case (i.e. you effectively get
the same result as with quasipoisson()).

I don't know what the rationale is for this, but it is clear that with
your data, an estimated dispersion parameter is going to be large. E.g.
the data has both 0 cases in 75 person-years and 1000 cases in 5000
person-years for Denmark, and in your model they are supposed to have
the same Poisson rate.

summary.svyglm starts off with

est.disp <- TRUE

and AFAICS there is no way it can get set to FALSE.  Knowing Thomas,
there is probably a perfectly good reason not to just set the dispersion
to 1, but I don't get it either...



Thanks
Laust

# loading survey
library(survey)

# creating data
listc <- 
c("Denmark","Finland","Norway","Sweden","Denmark","Finland","Norway","Sweden")
listw <- c(1,2,1,1,1,1,1,1)
listd <- c(0,0,0,0,1000,1000,1000,2000)
listt <- c(75,50,90,190,5000,5000,5000,1)
list.cwdt <- c(listc, listw, listd, listt)
country <- data.frame(country=listc,weight=listw,deaths=listd,yrs_at_risk=listt)

# running a frequency weighted regression to get the correct point
estimates for comparison
glm <- glm(deaths ~ country + offset(log(yrs_at_risk)),
weights=weight, data=country, family=poisson())
summary(glm)
regTermTest(glm, ~ country)

# running survey weighted regression
svy <- svydesign(~0,,data=country, weight=~weight)
svyglm <- svyglm(deaths ~ country + offset(log(yrs_at_risk)),
design=svy, data=country, family=poisson())
summary(svyglm)
# point estimates are correct, but standard error is way too large
regTermTest(svyglm, ~ country)
# test indicates no country differences

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



--
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - (p.dalga...@biostat.ku.dk)  FAX: (+45) 35327907

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


Re: [R] [Beginner] Issue with the barplot function

2009-10-10 Thread Jim Lemon

On 10/10/2009 06:34 PM, tulesparo wrote:

Hello,

I am a beginner with R and I would need some help with doing the barplot I
want.

In fact I want to draw a barplot from my table, but the issue is that only
the modalities with nonzero values are plotted ; the fact is that I would
plot all the modalities, including those which have no value.

If I'm not clear, here is an example : let X, Y and Z be three modalities
which have respectively 2, 0 and 3 values ; my current barplot only draws X
and Z, and I also would draw Y.


   

Hi tulesparo,
If you mean something like this:

xyz<-matrix(c(2,6,NA,NA,NA,NA,4,7,1),ncol=3)
barplot(xyz,beside=TRUE)

you can get zero height bars for y like this:

xyz[is.na(xyz)]<-0
barplot(xyz,beside=TRUE)


PS : Sorry if I've made mistakes, I'm French...
   

Ne vous inquiétez pas, mon ami, ce n'est pas votre faute.

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] plotting points in random but different colors based on condition

2009-10-10 Thread Jim Lemon

On 10/10/2009 06:41 PM, Jim Lemon wrote:

Oops, should be:



gimmeDiffCol<-function(oldcol) {
 rgbcomp<-col2rgb(oldcol)
 if(rgbcomp[1,1]<127) newred<-sample(rgbcomp[1,1]:255,1)/255
 else newred<-sample(0:rgbcomp[1,1],1)/255
 if(rgbcomp[2,1]<127) newgreen<-sample(rgbcomp[2,1]:255,1)/255
 else newgreen<-sample(0:rgbcomp[2,1],1)/255
  if(rgbcomp[3,1]<127) newblue<-sample(rgbcomp[3,1]:255,1)/255
 else newblue<-sample(0:rgbcomp[3,1],1)/255
 return(rgb(newred,newgreen,newblue))
}


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.


[R] [Beginner] Issue with the barplot function

2009-10-10 Thread tulesparo

Hello,

I am a beginner with R and I would need some help with doing the barplot I
want.

In fact I want to draw a barplot from my table, but the issue is that only
the modalities with nonzero values are plotted ; the fact is that I would
plot all the modalities, including those which have no value.

If I'm not clear, here is an example : let X, Y and Z be three modalities
which have respectively 2, 0 and 3 values ; my current barplot only draws X
and Z, and I also would draw Y.

Can someone help me please ?
Thank you


PS : Sorry if I've made mistakes, I'm French...
-- 
View this message in context: 
http://www.nabble.com/-Beginner--Issue-with-the-barplot-function-tp25831788p25831788.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] lattice: passing multiple lty values to the key/legend

2009-10-10 Thread Deepayan Sarkar
On Thu, Oct 8, 2009 at 10:52 AM, Folkes, Michael
 wrote:
> hi all,
> It's not clear to me how (or if) I can pass multiple values for lty to a key 
> in xyplot?
> I've tried:  lines=list(lty=1:3), to no avail.
> Do I need to use something other than auto.key?
> (Deepayan, if you're out there, I have your book and must admit the answer 
> isn't jumping out at me.)

It's probably not spelled out as clearly as it could have been, but
see Section 7.1.6 (p 125).

-Deepayan

> thanks in advance!
> Michael Folkes
>
> example code:
> #
>
> xx<-data.frame(v1=rep(letters[1:3],rep(3,3)),v2=rep(1:3,3),v3=rep(1:3,rep(3,3)))
> xyplot(v3~v2,data=xx,
>  xlab='',
>  group=v1,type='l', lty=1:3  ,
>
>   auto.key=list(text = levels(as.factor(xx$v1)) , title='',
>          cex.title=.75,points=F,lines = T,cex=1, x = .5, y = -0.1,corner = 
> c(0, 0),
>          between=1,columns=3,between.columns=2),
>  )
>
>
> ___
> Michael Folkes
> Salmon Stock Assessment
> Canadian Dept. of Fisheries & Oceans
> Pacific Biological Station
> 3190 Hammond Bay Rd.
> Nanaimo, B.C., Canada
> V9T-6N7
> Ph (250) 756-7264 Fax (250) 756-7053  michael.fol...@dfo-mpo.gc.ca 
> 
>
>        [[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] xyplot#strips like ggplot?

2009-10-10 Thread Deepayan Sarkar
On Thu, Oct 8, 2009 at 6:54 AM, baptiste auguie
 wrote:
> Hi,
>
> Try the useOuterStrips function in the latticeExtra package.

...which is discussed in section 11.5 of the Lattice book.

-Deepayan

> HTH,
>
> baptiste
>
> 2009/10/8 Christian Ritter :
>> Dear all,
>>
>> I want to split the strips in xyplot and push them into the margins ...
>>
>> Tried to find this in common documentation (such as Deepayan's book) on
>> lattice ... but so far without success ...

[...]

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


Re: [R] how to make the tick character in Y-axis to be horizontal?

2009-10-10 Thread Jim Lemon

On 10/10/2009 11:41 AM, Jie TANG wrote:

hello ,every one ,
  I draw a figure as shown in appendix A,
   The tick characters in the Y-axis is arranged in the vertical
direction.Now I want to arranged the Y-axis tick in the horizontal
direction.

How could I do ,then?
   

Hi Jie,

Try this:

par(las=1)
# then do your plot

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] plotting points in random but different colors based on condition

2009-10-10 Thread Jim Lemon

On 10/10/2009 11:10 AM, Jonathan Bleyhl wrote:

On a similar note, I'm trying to plot continuous values on the y vs.
categorical (dates) on the x and I want to color by date, but I want the
colors to be random so points close to each other are easily
distinguishable. Any thoughts?

Thanks,
Jon


per freem-2 wrote:
   

hi all,

suppose I have a file with several columns, and I want to plot all points
that meet a certain condition (i.e. all points in columns A and B that
have
a value greater than such and such in column C of the data) in a new but
random color.  That is, I want all these points to be colored differently
but I dont care what color.  The only concern is that the points will be
colored as differently from each other as possible.

The specific example I have is a file with three columns, X, Y and ID.  I
want to plot all rows from X, Y (i.e. all points) that have the same value
(say 1) in their ID column as one color, all points from X, Y that have
the
same ID column value (say 2) as a different color, etc.  I dont know ahead
of time how many values the ID column will have so I can't write a
separate
plot statement for each of these sets of X, Y rows that have the same ID
value.

Is there a way to express this in R?
 

Hi per freem and Jonathan,
Random colors may not do what you want simply because they're random. 
That is, you can get two adjacent colors that are very similar unless 
you constrain the choice of colors. One way to do this is to bias the 
choice of color constituents "away" from the previous color.


gimmeDiffCol<-function(oldcol) {
 rgbcomp<-col2rgb(oldcol)
 if(rgbcomp[1,1]>127) newred<-sample(rgbcomp[1,1]:255,1)/255
 else newred<-sample(0:rgbcomp[1,1],1)/255
 if(rgbcomp[2,1]>127) newgreen<-sample(rgbcomp[2,1]:255,1)/255
 else newgreen<-sample(0:rgbcomp[2,1],1)/255
  if(rgbcomp[3,1]>127) newblue<-sample(rgbcomp[3,1]:255,1)/255
 else newblue<-sample(0:rgbcomp[3,1],1)/255
 return(rgb(newred,newgreen,newblue))
}

This is only one way to do this, but it might get you out of trouble.

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.


[R] easy way to find all extractor functions and the datatypes of what they return

2009-10-10 Thread Robert Wilkins
Am I asking for too much:
for any object that a stat proc returns  ( y <- lm( y~x) , etc ) ) , is there
a super convenient function like give_all_extractors( y ) that lists all
extractor functions , the datatype returned , and a text descriptor
field ("pairwisepval" "lsmean" etc)

That would just be so convenient.

What are my options for querying an object so that I can quickly learn
the extractor functions to pull out the data and manipulate it?
Will the datatypes returned usually be named vectors and named
matrices, indiced by categorical values in the data
( "Male" "Female"  "Placebo" "DrugB" etc )? If they are indexed by 1 ,
2 , 3 , 4 , it's easier to lose track.

thanks a bunch in advance

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


Re: [R] auto.key legend color different from actual plot

2009-10-10 Thread Rene
Dear All,

 

I have created a barchart, but the legend created by auto.key does not match
the actual graph. Can someone give me some hint here?

 

For example, my coding are:

 

Library(lattice)

dataset.table <-
table(data.frame(id=c("a","b","c","a","c","b","a"),colour=c("blue","green","
red","red","red","green","green")))

blue<-hcl(238,60,100)

green<-hcl(120,70,100)

violet<-hcl(350,100,100)

barchart(rbind(dataset.table),horizontal =
FALSE,col=c(blue,green,violet),stack=FALSE, auto.key=TRUE)

 

 

As you can see, the actual plot, the color is blue, green then violet, but
in the legend, it is blue, violet and green. Can someone help me correct the
legend colour?

 

 

Thanks a lot.

 

Rene.

 

 

 

 


[[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] Display more than one plot

2009-10-10 Thread Jim Lemon

On 10/10/2009 01:51 PM, emkayenne wrote:

Nobody? :-(

emkayenne wrote:
   

Hello, I'm pretty new to R and I am having a hrd time getting a grip. Just
a question: can someone tell me how to have more than one graphics windown
open at the same time? I want to look at some plote at the same time...,
how is this done? If someone has a suggestion for a (good) introductory
guide to R, much appreciated, but not the manual..., this one I do have.
:confused:
 

Hi Emkay,
If you open another plotting device, e.g.

x11()

it will then be the active device until you shut it down or change the 
active device. See the dev.* functions in the grDevices package.


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] Running R scripts from a GUI interface

2009-10-10 Thread glen_b



Jason Rupert wrote:
> 
> I am curious if there is a typical approach for developing a GUI to run R
> scripts or to export R scripts in a DLL or other format so that they can
> be run from such a GUI. 
> 
> I also have not settled on a GUI development language so any suggestions
> there are also very much appreciated.  
> 

R Commander http://cran.r-project.org/web/packages/Rcmdr/index.html
is a basic stats GUI in R that provides a way for others to make a simple 
GUI interface to a package. Many R packages have GUI versions that work 
with R Commander.

It would seem to be a fairly simple way to do it. 

-- 
View this message in context: 
http://www.nabble.com/Running-R-scripts-from-a-GUI-interface-tp25831129p25831651.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.