Re: [R] ctree question

2012-01-18 Thread Achim Zeileis

On Wed, 18 Jan 2012, seanstcl...@verizon.net wrote:



  Hello.  I have used the "party" package to generate a regression tree as
  follows:

  >origdata<-read.csv("origdata.csv")
  >ctrl<-ctree_control(mincriterion=0.99,maxdepth=10,minbucket=10)
  >test.ct<-ctree(Y~X1+X2+X3,data=origdata,control=ctrl)

  The above works fine.  Orig data was my training data.  I now have a test
  data file (testdata), and would like to run the testdata through the above
  tree to see predictions.  I tried using the following function

  >predict(test.ct,newdata=testdata)

  but I get the following error:

  Error in checkData(oldData, RET) :
Levels in factors of new data do not match original data

  I've looked at the testdata file closely and it does not appear to contain
  any levels of factors that were not in the original.


Did you check carefully enough? compare

levels(origdata$X1)
levels(testdata$X1)

and so on for X2 and X3. Maybe the _observed_ levels in the testdata are 
ok but not all levels.

Z


  What might I be doing
  incorrectly, and how can i use the tree that was generated above to
  generate predictions for this new file testdata?

  THanks.
  sean
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Interpreting script - write.csv

2012-01-18 Thread Berend Hasselman

On 19-01-2012, at 04:48, Jhope wrote:

> Hi All, 
> 
> I am a beginner to R and a prof helped me with some script. I am having
> trouble understanding the below line. Is it finding the file
> turtlehatch.csv? I do not have my working directory set to this file. If so
> I tried ("file.choose") and it did not work. R did nothing in response, no
> error message with this entry and the below entry. 
> 
> Can you please help me interpret? :
> 
> write.csv(data.to.analyze, "turtlehatch.csv", row.names=FALSE)


Read the help for write.csv.

?write.csv

Berend

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

2012-01-18 Thread Sri krishna Devarayalu Balanagu
Hi All,


Can you please help me, why this code in not generating line chart?



library(ggplot2)
par(mfrow=c(1,3))

#qplot(TIME1, BASCHGA, data=Orange1, geom= c("point", "line"), colour= ACTTRT)
unique(Orange1$REFID) -> refid
for (i in refid)
{
Orange2 <- Orange1[i == Orange1$REFID, ]
pdf('PGA.pdf')
qplot(TIME1, BASCHGA, data=Orange2, geom= c("line"), colour= ACTTRT)
dev.off()
}
Regards,
Devarayalu

[[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] Interpreting script - write.csv

2012-01-18 Thread Jhope
Hi All, 

I am a beginner to R and a prof helped me with some script. I am having
trouble understanding the below line. Is it finding the file
turtlehatch.csv? I do not have my working directory set to this file. If so
I tried ("file.choose") and it did not work. R did nothing in response, no
error message with this entry and the below entry. 

Can you please help me interpret? :

write.csv(data.to.analyze, "turtlehatch.csv", row.names=FALSE)

Thanks,  J

--
View this message in context: 
http://r.789695.n4.nabble.com/Interpreting-script-write-csv-tp4309068p4309068.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] R help

2012-01-18 Thread Jhope
I am a beginner too to R and this forum! I signed onto this forum yesterday
and received help overnight! I have also learn a bit by reading the posts. I
took someone's suggestion and made a rule for my Inbox to filter the R
emails into this folder and the listserve is now working very well for me. 

Thank you for the support R help!

J

--
View this message in context: 
http://r.789695.n4.nabble.com/R-help-tp4306421p4308809.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] Error in variable ' _' converted to a factor AND *tmp*

2012-01-18 Thread Jhope
Thank you, I am new to R, and this forum. Aevent does not exist. I will also
try to post a better subject next time. 

--
View this message in context: 
http://r.789695.n4.nabble.com/Error-in-variable-converted-to-a-factor-AND-tmp-tp4305951p4308803.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] Filling color's points in legend's plot in R

2012-01-18 Thread Tsidkenu
Hi! I'm new with R and I'm trying to do some plots but I have a problem with
the legend of this graphic because I want to fill the color's points in the
legend and I don't find any form to do it.I will really appreciate your
help. This is the code for legend's plot:

 >legend(10,90,legend=c("TR=100 años","TR=50 años","TR=25 años","TR=10
años"),lwd=2,pt.cex=1.5,bty='n',pch=c(24,22,21,23))

And this is the plot: 
http://www.freeimagehosting.net/x94f8


--
View this message in context: 
http://r.789695.n4.nabble.com/Filling-color-s-points-in-legend-s-plot-in-R-tp4308966p4308966.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] ctree question

2012-01-18 Thread seanstclair

   Hello.  I have used the "party" package to generate a regression tree as
   follows:

   >origdata<-read.csv("origdata.csv")
   >ctrl<-ctree_control(mincriterion=0.99,maxdepth=10,minbucket=10)
   >test.ct<-ctree(Y~X1+X2+X3,data=origdata,control=ctrl)

   The above works fine.  Orig data was my training data.  I now have a test
   data file (testdata), and would like to run the testdata through the above
   tree to see predictions.  I tried using the following function

   >predict(test.ct,newdata=testdata)

   but I get the following error:

   Error in checkData(oldData, RET) :
 Levels in factors of new data do not match original data

   I've looked at the testdata file closely and it does not appear to contain
   any levels of factors that were not in the original.  What might I be doing
   incorrectly, and how can i use the tree that was generated above to generate
   predictions for this new file testdata?
   
   THanks.
   sean
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Executable expressions

2012-01-18 Thread baptiste auguie
One reason might be that you can easily fool the user into running
unexpected/unreadable commands. Guess what this does:

cmd <- paste(c(letters[c(19L, 25L, 19L, 20L, 5L, 13L)], "(' ",
letters[c(19L, 21L, 4L, 15L)], " ", letters[c(4L,
5L, 19L, 20L, 18L, 15L, 25L)], " ", letters[c(1L, 12L, 12L)], " ')"),
collapse="")

## not run
## eval(parse(text=cmd))

b.

On 19 January 2012 11:05, Wet Bell Diver  wrote:
>
> for my info, why is this rarely a good idea? Is that the case for this
> particular example , or is eval(paste()) generally rarely a good idea?
>
> --Peter
>
> Op 18-1-2012 22:22, R. Michael Weylandt schreef:
>
>> eval(parse(text = a))
>>
>> But this is rarely a good ideaperhaps you could say a little more
>> about your overall goal and we could direct you to a more "R"-ish
>> solution?
>>
>> library(fortunes)
>> fortune("rethink")
>>
>> Michael
>>
>> On Wed, Jan 18, 2012 at 4:18 PM, Ajay Askoolum
>>  wrote:
>>>
>>> Given
>>>
>>> a<-"c(1,2,3,4,5)"
>>>
>>> How can  I evaluate the variable a to return a (numeric) vector
>>> comprising of 1,2,3,4,5? Thanks.
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] graph paper look

2012-01-18 Thread Pete Brecknock

Erin Hodgess-2 wrote
> 
> Dear R People:
> 
> Short of doing a series of ablines, is there a way to produce "graph
> paper" in R please?
> 
> Thanks,
> Erin
> 
> 
> -- 
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences
> University of Houston - Downtown
> mailto: erinm.hodgess@
> 
> __
> R-help@ mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

How about ...

x = rnorm(100)
y = rnorm(100)
plot(x,y)
grid()

HTH

Pete

--
View this message in context: 
http://r.789695.n4.nabble.com/graph-paper-look-tp4308827p4308906.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] graph paper look

2012-01-18 Thread Ben Bolker
Erin Hodgess  gmail.com> writes:

> Short of doing a series of ablines, is there a way to produce "graph
> paper" in R please?

  How about ?grid ...

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


Re: [R] graph paper look

2012-01-18 Thread baptiste auguie
You could draw a grid with grid, using grid.grill,

library(grid)

pdf("grid.pdf", width=21/2.54,height=29.7/2.54)
grid.grill(h = unit(seq(0, 297, by=1), "mm"),
   v = unit(seq(0, 210, by=1), "mm"), gp=gpar(col="grey",lwd=0.1))
grid.grill(h = unit(seq(0, 297, by=5), "mm"),
   v = unit(seq(0, 210, by=5), "mm"), gp=gpar(col="grey20",lwd=0.2))
grid.grill(h = unit(seq(0, 29.7, by=1), "cm"),
   v = unit(seq(0, 21, by=1), "cm"), gp=gpar(col="black",lwd=1))
dev.off()

HTH,

b.


On 19 January 2012 14:18, Erin Hodgess  wrote:
> Dear R People:
>
> Short of doing a series of ablines, is there a way to produce "graph
> paper" in R please?
>
> Thanks,
> Erin
>
>
> --
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences
> University of Houston - Downtown
> mailto: erinm.hodg...@gmail.com
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] graph paper look

2012-01-18 Thread Erin Hodgess
Dear R People:

Short of doing a series of ablines, is there a way to produce "graph
paper" in R please?

Thanks,
Erin


-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@gmail.com

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


[R] venn.diagram how to control circle diameter

2012-01-18 Thread Mikael Johnson
Hi there,
Is there a way to control the circle diameter in venn.diagram function of
VennDiagram package?
Thanks
Mike

[[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] Executable Expressions II

2012-01-18 Thread Ajay Askoolum
I am not using RExcel at all.

I have now come up with a better solution that using eval. I can construct the 
data structure (like c(1,2,3,4,5)) as an object in C# and pass it as the 
argument to the method inside the web service that will call R. Works fine.
[[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] makeCluster() function in doSNOW package hangs

2012-01-18 Thread Michael Krabbe Borregaard
Dear R help,

I am trying to set up a cluster for parallel computing on a machine
running 64-bit windows XP, using the doSNOW package on R 2.14.1.
However, the command makeCluster() consistently makes the computer hang.
No R processes are started, no CPU consumed, R just becomes
unresponsive. ESC still terminates the command, but I cannot start the
cluster. There seems to be quite a lot of posts on R-help with this or a
similar problem, but none of them are resolved. 

I have been going through the internal commands in the function, and it
is the call to socketConnection(host, etc...) that is responsible for
hanging, though I cannot see why. The command works on two other
machines I have with Windows 7. Intriguingly, it apparently also works
when my colleague logs on to the very same machine (remotely) with his
logon details! But not for me, alas. I am an administrator of the
machine so that should not be responsible for the problem. I also tried
running R as administrator, but that does not cure the problem. I have
turned off windows firewall completely to prevent that from causing
problems.

I tried uninstalling R and reinstalling several times. The problem
persists, and both under 32-bit and 64-bit versions. I also tried
deleting the library completely before reinstalling, and installing all
packages from scratch, to see if there could be a fault there, but that
did not help.

Any help will be greatly appreciated,

Best wishes,

 

Michael Krabbe Borregaard

Post doctoral research fellow

Center for Macroecology, Evolution and Climate

University of Copenhagen

Denmark

 

 


[[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] png output on a server?

2012-01-18 Thread Justin Haynes
I've got R running on a gentoo server that doesn't have X11 installed.  Its
a custom build to keep those dependencies at bay!  However, some of my
scripts use the base png() function and ggplot2. But, png uses X11.

A google search suggests using the Cairo package, which works... but
changes the fonts (specifically the size of the font).  Adjusting the
pointsize doesn't seem to have much effect.

Aside from tuning the CairoPNG function to make my graphs look right, has
anyone found a good way to avoid the X11 dependency but still use the base
png function?

If anyone has experience with CairoPNG and making it look like the base png
function, id love to hear what you've learned!


Thanks,

Justin


> capabilities()
jpeg  png tifftcltk  X11 aqua http/ftp  sockets
libxml fifo   clediticonv  NLS  profmem
   FALSEFALSEFALSEFALSEFALSEFALSE TRUE TRUE
TRUE TRUE TRUE TRUE TRUEFALSE
   cairo
   FALSE
>

> sessionInfo()
R version 2.14.1 (2011-12-22)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8LC_PAPER=C
  LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] Cairo_1.5-1   ggplot2_0.8.9 proto_0.3-9.2 reshape_0.8.4 plyr_1.7.1

loaded via a namespace (and not attached):
[1] tools_2.14.1
>

[[alternative HTML version deleted]]

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


Re: [R] R package dev: how to export constant?

2012-01-18 Thread Jonas Stein
On 2012-01-18, William Dunlap  wrote:
> Try adding
>   LazyData: yes
> to the DESCRIPTION file.
>> [3] https://github.com/jonasstein/sitools

Thank you. Now it works and I could add all SI prefixes.


-- 
Jonas Stein 

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


[R] [R-pkgs] New package knitr

2012-01-18 Thread Yihui Xie
The knitr package was designed to be a transparent engine for dynamic
report generation with R, solve some long-standing problems in Sweave,
and combine features in other add-on packages into one package. It is
a general-purpose package, and currently supports LaTeX, HTML and
Markdown (still extensible).

See the package website [1] to get started; see the package manuals
([2], [3] and [4]) for a quick overview of what knitr can do; see the
demos [5] for other examples.

[1] http://yihui.github.com/knitr/
[2] https://github.com/downloads/yihui/knitr/knitr-manual.pdf
[3] https://github.com/downloads/yihui/knitr/knitr-graphics.pdf
[4] https://github.com/downloads/yihui/knitr/knitr-themes.pdf
[5] http://yihui.github.com/knitr/demos

This package is available on the main CRAN site now, and you may need
to wait for a few days for it to be mirrored to a CRAN site near to
you.

Feedback, bug report and feature request are welcome: use
https://github.com/yihui/knitr/issues or
https://groups.google.com/group/knitr or StackOverflow or r-help.

Regards,
Yihui
--
Yihui Xie 
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

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


Re: [R] drop rare factors

2012-01-18 Thread Sarah Goslee
Here's one way, worked out in lots of steps so you can see
how each works:

> mydata <- data.frame(MyFactor = factor(rep(LETTERS[1:4], times=c(1000, 2000, 
> 30, 4))), something = runif(3034))
> str(mydata)
'data.frame':   3034 obs. of  2 variables:
 $ MyFactor : Factor w/ 4 levels "A","B","C","D": 1 1 1 1 1 1 1 1 1 1 ...
 $ something: num  0.725 0.222 0.347 0.614 0.968 ...
>
> table(mydata$MyFactor)

   ABCD
1000 2000   304
>
>
> important.levels <- table(mydata$MyFactor) / nrow(mydata)
> important.levels <- names(important.levels)[important.levels > .01]
> important.levels
[1] "A" "B"
>
> newdata <- mydata[mydata$MyFactor %in% important.levels, ]
> table(newdata$MyFactor)

   ABCD
1000 200000
>
>
> newdata$MyFactor <- factor(newdata$MyFactor, levels=important.levels)
> table(newdata$MyFactor)

   AB
1000 2000
>


On Wed, Jan 18, 2012 at 5:25 PM, Sam Steingold  wrote:
> I have a data frame with some factor columns.
> I want to drop the rows with rare factor values
> (and remove the factor values from the factors).
> E.g.,  frame$MyFactor takes values
> A 1,000 times,
> B 2,000 times,
> C 30 times and
> D 4 times.
> I want to remove all rows which assume rare values (<1%), i.e., C and D.
> i.e.,
> frame <- frame[[! (frame$MyFactor %in% c("A","B"))]]
> except that I probably got the syntax wrong
> and I want c("A","B") to be generated automatically from frame$MyFactor
> and the number 0.01 (1%).
>
> Thanks!

-- 
Sarah Goslee
http://www.functionaldiversity.org

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


[R] drop rare factors

2012-01-18 Thread Sam Steingold
I have a data frame with some factor columns.
I want to drop the rows with rare factor values
(and remove the factor values from the factors).
E.g.,  frame$MyFactor takes values
A 1,000 times,
B 2,000 times,
C 30 times and
D 4 times.
I want to remove all rows which assume rare values (<1%), i.e., C and D.
i.e.,
frame <- frame[[! (frame$MyFactor %in% c("A","B"))]]
except that I probably got the syntax wrong
and I want c("A","B") to be generated automatically from frame$MyFactor
and the number 0.01 (1%).

Thanks!
-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://thereligionofpeace.com http://mideasttruth.com http://memri.org
http://palestinefacts.org http://dhimmi.com http://truepeace.org
DRM "access management" == prison "freedom management".

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


Re: [R] Problem importing .txt file

2012-01-18 Thread R. Michael Weylandt
Responses will be sent to the list and bounced to you if you are
subscribed: most replies also cc the thread and OP (and I think the
server notes this so you don't get two copies).

It looks like it may be an encoding problem in the .txt file. If your
data allows it, try opening it up with a text editor and saving it
again as something like Latin-1. Everything looks ok on the R end of
things.

Michael

On Wed, Jan 18, 2012 at 4:39 PM, Berneet Kaur
 wrote:
>
>
>   Hello, I hope I am doing this correctly, though I am not sure if a response
>   will be posted somewhere or if I will get a direct response. I am trying to
>   import a .txt table in my class on R and for some reason, the header gets
>   altered and I can no longer read the data. No one in my class had this
>   problem and the instructors were not sure how to fix it.
>   Here is the text table:
>   Kind Fatness Wt
>   Ewe 4 10.3
>   Ewe 8 11.9
>   Ewe 11 15
>   Ewe 15 17.1
>   Ewe 15 18.7
>   Ram 5 12.4
>   Ram 4 14.3
>   Ram 10 16.6
>   Ram 8 18.8
>   Ram 14 21.9
>   Here is the code that I copied from the instructors handout (simple cut and
>   paste, no alterations):
>   Lambs = read.table("Lambs.txt", header = TRUE)
>   > Lambs
>   ï..Kind Fatness Wt
>   1 Ewe 4 10.3
>   2 Ewe 8 11.9
>   3 Ewe 11 15.0
>   4 Ewe 15 17.1
>   5 Ewe 15 18.7
>   6 Ram 5 12.4
>   7 Ram 4 14.3
>   8 Ram 10 16.6
>   9 Ram 8 18.8
>   10 Ram 14 21.9
>   > par(mfrow = c(1, 2))
>   > plot(Fatness ~ Kind, data = Lambs)
>   Error in eval(expr, envir, enclos) : object 'Kind' not found
>
>
>   I think it is because the "Kind" header got altered into " ï..Kind" and it
>   can no longer identify the object.
>   Can anyone help?
>   Thanks
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Problem importing .txt file

2012-01-18 Thread Sarah Goslee
It's hard to diagnose the problem with importing the file without
the file itself, but you can easily change the column names:

colnames(Lambs) <- c("Kind", "Fatness", "Wt")

You should also open the text file itself and check that everything
looks okay with the first few rows.

Sarah

On Wed, Jan 18, 2012 at 4:39 PM, Berneet Kaur
 wrote:
>
>
>   Hello, I hope I am doing this correctly, though I am not sure if a response
>   will be posted somewhere or if I will get a direct response. I am trying to
>   import a .txt table in my class on R and for some reason, the header gets
>   altered and I can no longer read the data. No one in my class had this
>   problem and the instructors were not sure how to fix it.
>   Here is the text table:
>   Kind Fatness Wt
>   Ewe 4 10.3
>   Ewe 8 11.9
>   Ewe 11 15
>   Ewe 15 17.1
>   Ewe 15 18.7
>   Ram 5 12.4
>   Ram 4 14.3
>   Ram 10 16.6
>   Ram 8 18.8
>   Ram 14 21.9
>   Here is the code that I copied from the instructors handout (simple cut and
>   paste, no alterations):
>   Lambs = read.table("Lambs.txt", header = TRUE)
>   > Lambs
>   ï..Kind Fatness Wt
>   1 Ewe 4 10.3
>   2 Ewe 8 11.9
>   3 Ewe 11 15.0
>   4 Ewe 15 17.1
>   5 Ewe 15 18.7
>   6 Ram 5 12.4
>   7 Ram 4 14.3
>   8 Ram 10 16.6
>   9 Ram 8 18.8
>   10 Ram 14 21.9
>   > par(mfrow = c(1, 2))
>   > plot(Fatness ~ Kind, data = Lambs)
>   Error in eval(expr, envir, enclos) : object 'Kind' not found
>
>
>   I think it is because the "Kind" header got altered into " ï..Kind" and it
>   can no longer identify the object.
>   Can anyone help?
>   Thanks


-- 
http://www.functionaldiversity.org

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


Re: [R] Executable expressions

2012-01-18 Thread Wet Bell Diver


for my info, why is this rarely a good idea? Is that the case for this 
particular example , or is eval(paste()) generally rarely a good idea?


--Peter

Op 18-1-2012 22:22, R. Michael Weylandt schreef:

eval(parse(text = a))

But this is rarely a good ideaperhaps you could say a little more
about your overall goal and we could direct you to a more "R"-ish
solution?

library(fortunes)
fortune("rethink")

Michael

On Wed, Jan 18, 2012 at 4:18 PM, Ajay Askoolum  wrote:

Given

a<-"c(1,2,3,4,5)"

How can  I evaluate the variable a to return a (numeric) vector comprising of 
1,2,3,4,5? Thanks.

[[alternative HTML version deleted]]


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


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


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


Re: [R] R-Help

2012-01-18 Thread Sarah Goslee
A reproducible example would be really helpful here, but I think what
you want is:
table(NumberOfActionsByUser, NumberOfBidOffer)

On Wed, Jan 18, 2012 at 3:49 PM, caam  wrote:
> I am trying to create a frequency distribution and I am a bit confused.
>
> Here are the commands I have entered:
>
>> data <- read.csv(file="40609_sortedfinal.csv",head=TRUE,sep=",")
>> NumberOfActionsByStatus = data$STATUS
>> NumberOfActionsByUser = data$ETS_LOGIN
>> NumberOfBidOffer = data$BID_OFFER
>> NumberOfActionsByUser.freq = table(NumberOfActionsByUser)
>> NumberOfBidOffer.freq = table(NumberOfBidOffer)
>> NumberOfActionsByStatus.freq = table(NumberOfActionsByStatus)
>
>
> After doing that above, I was able to see the freq. distribution of contents
> in each.
>
>> cbind(NumberOfBidOffer.freq)
>      NumberOfBidOffer.freq
> Bid                  178074
> Offer                179540
>
>> cbind(NumberOfActionsByUser.freq)
>             NumberOfActionsByUser.freq
> A                             22
> B                               2
> C                            29028
> D                        328054
> E                        187
> F                               7
> G                             2
> H                               4
> I                              308
>
> 
>
> Now, what I am having a problem with is, I want to then output a freq
> distribution that shows out of the 22 actions by A.. how many of those
> actions were BID and how many of those were OFFER.
>
> I would like to do that for each user; ie.  A->F
>
> What is the best command to do this?
>
> Any help would be appreciated,
>
> Best,
>
> SA
>
>

-- 
Sarah Goslee
http://www.functionaldiversity.org

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


[R] Problem importing .txt file

2012-01-18 Thread Berneet Kaur


   Hello, I hope I am doing this correctly, though I am not sure if a response
   will be posted somewhere or if I will get a direct response. I am trying to
   import a .txt table in my class on R and for some reason, the header gets
   altered and I can no longer read the data. No one in my class had this
   problem and the instructors were not sure how to fix it.
   Here is the text table:
   Kind Fatness Wt
   Ewe 4 10.3
   Ewe 8 11.9
   Ewe 11 15
   Ewe 15 17.1
   Ewe 15 18.7
   Ram 5 12.4
   Ram 4 14.3
   Ram 10 16.6
   Ram 8 18.8
   Ram 14 21.9
   Here is the code that I copied from the instructors handout (simple cut and
   paste, no alterations):
   Lambs = read.table("Lambs.txt", header = TRUE)
   > Lambs
   ï..Kind Fatness Wt
   1 Ewe 4 10.3
   2 Ewe 8 11.9
   3 Ewe 11 15.0
   4 Ewe 15 17.1
   5 Ewe 15 18.7
   6 Ram 5 12.4
   7 Ram 4 14.3
   8 Ram 10 16.6
   9 Ram 8 18.8
   10 Ram 14 21.9
   > par(mfrow = c(1, 2))
   > plot(Fatness ~ Kind, data = Lambs)
   Error in eval(expr, envir, enclos) : object 'Kind' not found


   I think it is because the "Kind" header got altered into " ï..Kind" and it
   can no longer identify the object.
   Can anyone help?
   Thanks
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] kmeans clustering on large but sparse matrix

2012-01-18 Thread Lishu Liu
Hi,

I have a 60k*600k matrix, which exceed the vector length limit of 2^32-1.
But it's rather sparse, only 0.02% has value. So I save is as MarketMatrix
(mm) file, it's about 300M in size. I use readMM in Matrix package to read
it in. If do so, the data type becomes dgTMatrix in 'Matrix' package
instead of the common matrix type.

The problem is, if I run k-means only on part of the data, to make sure the
vector length do not exceed 2^32-1, there's no problem at all. Meaning that
the kmeans in R could recognize this type of matrix.
If I run the entire matrix, R says "too many elements specified."

I have considered the 'bigmemory' and 'biganalytics' packages. But to save
the sparse matrix as common CSV file would take approx 70G and 99% being 0.
I just don't think it's necessary or efficient to treat it as a dense
matrix.

It there anyway to deal with the vector length limit? Can I split the whole
matrix into small ones and then do k-means?



Thanks,
Lishu

[[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] forecasting a time series

2012-01-18 Thread nhomeier
Couldn't find this in the archives. I'm fitting a series of historical
weather-related data, but would like to use the latest values to forecast.
So let's say that I'm using 1970-2000 to fit a model (using fourier terms
and arima/auto.arima), but now would like to use the last X values to
predict tomorrow's weather. I'm at a loss. All the functions I've come
across (like forecast()) use the series and then forecast from the end
point. 

Do I need to decompose the fit and write it out the long way? For example, 
Tomorrow = fit$coef[1]*Yesterday + fit$coef[2]*BeforeYesterday + etc

or is there a function that I'm not finding?

Thank you,
Nicole

--
View this message in context: 
http://r.789695.n4.nabble.com/forecasting-a-time-series-tp4308147p4308147.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] Executable Expressions II

2012-01-18 Thread Richard M. Heiberger
If you are using rcom from Excel, then you would send R the vector of
numbers containing the values you were
interested in and you would get the mean back.  I suggest you look at the
RExcel implementation and duplicate its
capabilities.  The rcom documentation includes examples in other languages
than Excel.  Followup should be on the
rcom mailing list rco...@mailman.csd.univie.ac.at, which I am including by
cc.  You will need to sign up for that list
at rcom.univie.ac.at
While there also look at the discussions on the wiki there.

Rich

On Wed, Jan 18, 2012 at 4:41 PM, Ajay Askoolum  wrote:

> Thank you Michael, Sarah and Robin for the answers to my original question.
>
> Michael you asked:"But this is rarely a good ideaperhaps you could say
> a little more
> about your overall goal and we could direct you to a more "R"-ish
> solution? "
>
> I realise eval (known as execute in one of my other languages) is not a
> good idea. The background to my question is as follows:
>
> Using rcom & rscproxy, I can deploy R as a COM server inside a C# or VB
> SOAP Web Service. Any methods that I write in the web service, will need
> input (or arguments) of unknown length or type etc.
>
>
> Say, (trivial example) I wanted R to give me the mean, median of
> c(1,2,3,4,5), I can pass c(1,2,3,4,5) as the argument, have R eval it &
> return the results.
>
> Do I make sense?
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] R-Help

2012-01-18 Thread caam
I am trying to create a frequency distribution and I am a bit confused.

Here are the commands I have entered:

> data <- read.csv(file="40609_sortedfinal.csv",head=TRUE,sep=",")
> NumberOfActionsByStatus = data$STATUS
> NumberOfActionsByUser = data$ETS_LOGIN
> NumberOfBidOffer = data$BID_OFFER
> NumberOfActionsByUser.freq = table(NumberOfActionsByUser)
> NumberOfBidOffer.freq = table(NumberOfBidOffer)
> NumberOfActionsByStatus.freq = table(NumberOfActionsByStatus)


After doing that above, I was able to see the freq. distribution of contents
in each.

> cbind(NumberOfBidOffer.freq)
  NumberOfBidOffer.freq
Bid  178074
Offer179540

> cbind(NumberOfActionsByUser.freq)
 NumberOfActionsByUser.freq
A 22
B   2
C29028
D328054
E187
F   7
G 2
H   4
I  308



Now, what I am having a problem with is, I want to then output a freq
distribution that shows out of the 22 actions by A.. how many of those
actions were BID and how many of those were OFFER.

I would like to do that for each user; ie.  A->F

What is the best command to do this? 

Any help would be appreciated,

Best,

SA


--
View this message in context: 
http://r.789695.n4.nabble.com/R-Help-tp4308052p4308052.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] Warning on R CMD check

2012-01-18 Thread David L Lorenz
Michael,
I just checked. I've got 0.2.5. I'll update tonight and see if that fixes 
the problem.
Dave



From:
"R. Michael Weylandt" 
To:
David L Lorenz 
Cc:
"r-help@r-project.org" 
Date:
01/18/2012 03:32 PM
Subject:
Re: [R] Warning on R CMD check



Which version of lubridate do you have on your machine? I don't get
those warnings with the current CRAN version 0.2.6: it looks like
Hadley changed things to avoid that problem just a few weeks ago:
https://github.com/hadley/lubridate/tree/master/R (see the note on
zzz.R)

Michael

On Wed, Jan 18, 2012 at 4:22 PM, David L Lorenz  wrote:
> I am trying to check and build a package that requires another package
> that generates a warning, so the check step never really completes with 
no
> warnings.
>
> The package uses some routines in the lubridate package, but when the
> lubridate package is loaded for the check, I get these warnings:
>
> Found the following significant warnings:
>  Warning: changing locked binding for '+.Date' in 'base' whilst loading
> 'lubridate'
>  Warning: changing locked binding for '+.POSIXt' in 'base' whilst 
loading
> 'lubridate'
>  Warning: changing locked binding for '-.Date' in 'base' whilst loading
> 'lubridate'
>  Warning: changing locked binding for '-.POSIXt' in 'base' whilst 
loading
> 'lubridate'
>  Warning: changing locked binding for '/.difftime' in 'base' whilst
> loading 'lubridate'
>
> Everything else now checks out OK.
>
> Is this a big issue?
> Can I avoid the error by specifically referring to the functions that I
> need instead of loading the library?
> Does the last one cahnge what is specified in the DESCRIPTION file?
>
> Thanks.
> Dave
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



[[alternative HTML version deleted]]

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


[R] Executable Expressions II

2012-01-18 Thread Ajay Askoolum
Thank you Michael, Sarah and Robin for the answers to my original question.

Michael you asked:"But this is rarely a good ideaperhaps you could say a 
little more 
about your overall goal and we could direct you to a more "R"-ish solution? "

I realise eval (known as execute in one of my other languages) is not a good 
idea. The background to my question is as follows:

Using rcom & rscproxy, I can deploy R as a COM server inside a C# or VB SOAP 
Web Service. Any methods that I write in the web service, will need input (or 
arguments) of unknown length or type etc. 


Say, (trivial example) I wanted R to give me the mean, median of c(1,2,3,4,5), 
I can pass c(1,2,3,4,5) as the argument, have R eval it & return the results.

Do I make sense?
[[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] Executable expressions

2012-01-18 Thread Charlie Sharpsteen
On Wed, Jan 18, 2012 at 1:18 PM, Ajay Askoolum  wrote:
>
> Given
>
> a<-"c(1,2,3,4,5)"
>
> How can  I evaluate the variable a to return a (numeric) vector comprising of 
> 1,2,3,4,5? Thanks.


You can also use an "active binding":

    > makeActiveBinding('a', function(){c(1,2,3,4,5)}, .GlobalEnv)
    > a
    [1] 1 2 3 4 5

However, I agree with the other posters---resorting to these kinds of
tricks is usually a bad sign.

-Charlie

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


Re: [R] Warning on R CMD check

2012-01-18 Thread R. Michael Weylandt
Which version of lubridate do you have on your machine? I don't get
those warnings with the current CRAN version 0.2.6: it looks like
Hadley changed things to avoid that problem just a few weeks ago:
https://github.com/hadley/lubridate/tree/master/R (see the note on
zzz.R)

Michael

On Wed, Jan 18, 2012 at 4:22 PM, David L Lorenz  wrote:
> I am trying to check and build a package that requires another package
> that generates a warning, so the check step never really completes with no
> warnings.
>
> The package uses some routines in the lubridate package, but when the
> lubridate package is loaded for the check, I get these warnings:
>
> Found the following significant warnings:
>  Warning: changing locked binding for '+.Date' in 'base' whilst loading
> 'lubridate'
>  Warning: changing locked binding for '+.POSIXt' in 'base' whilst loading
> 'lubridate'
>  Warning: changing locked binding for '-.Date' in 'base' whilst loading
> 'lubridate'
>  Warning: changing locked binding for '-.POSIXt' in 'base' whilst loading
> 'lubridate'
>  Warning: changing locked binding for '/.difftime' in 'base' whilst
> loading 'lubridate'
>
> Everything else now checks out OK.
>
> Is this a big issue?
> Can I avoid the error by specifically referring to the functions that I
> need instead of loading the library?
> Does the last one cahnge what is specified in the DESCRIPTION file?
>
> Thanks.
> Dave
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Executable expressions

2012-01-18 Thread Robin Cura
Hi

eval(parse(text=a)) should do the trick :)

Cheers,

Robin

2012/1/18 Ajay Askoolum 

> Given
>
> a<-"c(1,2,3,4,5)"
>
> How can  I evaluate the variable a to return a (numeric) vector comprising
> of 1,2,3,4,5? Thanks.
>
>[[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

[[alternative HTML version deleted]]

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


Re: [R] Executable expressions

2012-01-18 Thread Sarah Goslee
> mytext <- "c(1,2,3,4,5)"
> a <- eval(parse(text=mytext))
> a
[1] 1 2 3 4 5

will do this, if there's no better way to accomplish your actual goal.

Sarah

On Wed, Jan 18, 2012 at 4:18 PM, Ajay Askoolum  wrote:
> Given
>
> a<-"c(1,2,3,4,5)"
>
> How can  I evaluate the variable a to return a (numeric) vector comprising of 
> 1,2,3,4,5? Thanks.
>
>        [[alternative HTML version deleted]]
>
>


-- 
Sarah Goslee
http://www.functionaldiversity.org

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


Re: [R] Executable expressions

2012-01-18 Thread R. Michael Weylandt
eval(parse(text = a))

But this is rarely a good ideaperhaps you could say a little more
about your overall goal and we could direct you to a more "R"-ish
solution?

library(fortunes)
fortune("rethink")

Michael

On Wed, Jan 18, 2012 at 4:18 PM, Ajay Askoolum  wrote:
> Given
>
> a<-"c(1,2,3,4,5)"
>
> How can  I evaluate the variable a to return a (numeric) vector comprising of 
> 1,2,3,4,5? Thanks.
>
>        [[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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

2012-01-18 Thread David L Lorenz
I am trying to check and build a package that requires another package 
that generates a warning, so the check step never really completes with no 
warnings.

The package uses some routines in the lubridate package, but when the 
lubridate package is loaded for the check, I get these warnings:

Found the following significant warnings:
  Warning: changing locked binding for '+.Date' in 'base' whilst loading 
'lubridate'
  Warning: changing locked binding for '+.POSIXt' in 'base' whilst loading 
'lubridate'
  Warning: changing locked binding for '-.Date' in 'base' whilst loading 
'lubridate'
  Warning: changing locked binding for '-.POSIXt' in 'base' whilst loading 
'lubridate'
  Warning: changing locked binding for '/.difftime' in 'base' whilst 
loading 'lubridate'

Everything else now checks out OK.

Is this a big issue?
Can I avoid the error by specifically referring to the functions that I 
need instead of loading the library?
Does the last one cahnge what is specified in the DESCRIPTION file?

Thanks.
Dave

[[alternative HTML version deleted]]

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


[R] Executable expressions

2012-01-18 Thread Ajay Askoolum
Given

a<-"c(1,2,3,4,5)"

How can  I evaluate the variable a to return a (numeric) vector comprising of 
1,2,3,4,5? Thanks.

[[alternative HTML version deleted]]

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


Re: [R] CairoPDF and greek letter spacing

2012-01-18 Thread James Cloos
> "RT" == Rolf Turner  writes:

RT> Compare:

RT> require(lattice)
RT> cairo_pdf(file="mung.pdf")
RT> 
print(xyplot(y~x,data=data.frame(x=1:10,y=1:10),main=expression(Length==mu*m)))
RT> dev.off()
RT> and
RT> pdf(file="gorp.pdf")
RT> 
print(xyplot(y~x,data=data.frame(x=1:10,y=1:10),main=expression(Length==mu*m)))
RT> dev.off()

After using qpdf(1) to uncompress the pdfs, the latter produces:

BT
/F6 1 Tf 14.00 0.00 -0.00 14.00 270.63 487.95 Tm (m) Tj
ET
BT
/F2 1 Tf 14.00 0.00 -0.00 14.00 278.69 487.95 Tm (m) Tj
ET

where /F6 is /Symbol and /F2 is /Helvetica.

The former produces:

14.399414 0 0 14.399414 209.167969 487.277344 Tm
% (Length =) elided
/f-2-0 1 Tf
0.786979 -0.00461173 Td
Tj
/f-0-0 1 Tf
0.625025 -0.0124788 Td
(m)Tj

where /f-2-0 is /DQHRIK+Symbol and f-0-0 is /OJZLOW+NimbusSanL-Regu.

In gorp, (m)’s start point is 8.06 units right of (μ)’s start point.

In mung, (m)’s start point is 0.161954 units right of (μ)’s end point.

The version of /DQHRIK+Symbol has a /mu with a width of 576 font units
and a 1000 unit em.  At 14.4pt that is a width of 8.294 pdf points.

Gorp does not have embedded fonts, but Adobe’s AFM file for /Symbol
also specified 576 font units for /mu’s width.  That line of text,
though is set at 14pt rather than 14.4pt, so a width of 8.064 pts.

It looks like all of the text in gorp is set tighter than in mung.

Perhaps using utf8 would look better:

  require(lattice)
  cairo_pdf(file="mung8.pdf", family="serif")
  print(xyplot(y~x,data=data.frame(x=1:10,y=1:10),main="Length = µm"))
  dev.off()

It certainly looks better here, with sans, serif or any font which has
latin and greek glyphs.  To do that with Latin Modern Roman, though, I
had to use U+00B5 MICRO SIGN (µ) rather than U+03BC GREEK SMALL LETTER MU.
(The snippet above uses MICRO SIGN.)

I think the takeaway is that cairo works better with a utf8 workflow.

-JimC
-- 
James Cloos  OpenPGP: 1024D/ED7DAEA6

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 exactly align the right hand side of "mtext" relative to a plot device? Beyond "adj".

2012-01-18 Thread Jean V Adams
George Shirreff wrote on 01/18/2012 01:14:55 PM:

> Hi,
> 
> I have a problem with aligning text which I'm adding to a plot using
> "mtext". I would like to specify the position of the right hand end of 
the
> text string, relative to the device (in the left-right direction).
> 
> I've been looking at the use of the argument "adj". But this can't be 
used
> to specify the rightmost point of the text. Neither does it specify 
exactly
> the centre of the text, so I'm not sure exactly how it works.
> 
> I could hack it and change "adj" accordingly but this is part of a 
function
> which I need to generalise. So it needs to be the same regardless of the
> length of the added text, or the values on the x-axis.
> 
> Here's a simple example with two versions (the first three lines of each
> version are identical). I would like the right end of the added text to 
be
> the same distance from the legend in both versions.
> 
> ### v1
> dev.new()
> plot(c(0,1),c(0,1),ylim=c(0,2))
> legend("topright",c("data1","data2"),col=c(1,2),lty=1,bty="n")
> mtext("text",side=3,line=-2,adj=0.8)
> 
> ### v2
> dev.new()
> plot(c(0,1),c(0,1),ylim=c(0,2))
> legend("topright",c("data1","data2"),col=c(1,2),lty=1,bty="n")
> mtext("really long text",side=3,line=-2,adj=0.8)
> 
> 
> Thank you for your help,
> George


You could take control of the position by calculating it yourself using 
the extremes of the plotting region, par("usr").  For example:

my.mtext <- function(my.adj, ...) {
xr <- par("usr")[1:2]
my.at <- xr[1]+my.adj*(xr[2] - xr[1])
mtext(at=my.at, ...)
}

### v1 
dev.new() 
plot(c(0,1),c(0,1),ylim=c(0,2)) 
legend("topright",c("data1","data2"),col=c(1,2),lty=1,bty="n") 
my.mtext(my.adj=0.8, text="text", side=3, line=-2, adj=1) 

### v2 
dev.new() 
plot(c(0,1),c(0,1),ylim=c(0,2)) 
legend("topright",c("data1","data2"),col=c(1,2),lty=1,bty="n") 
my.mtext(my.adj=0.8, text="really long text", side=3, line=-2, adj=1) 

Jean
[[alternative HTML version deleted]]

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


Re: [R] How do I exactly align the right hand side of "mtext" relative to a plot device? Beyond "adj".

2012-01-18 Thread Marc Schwartz
On Jan 18, 2012, at 1:14 PM, George Shirreff wrote:

> Hi,
> 
> I have a problem with aligning text which I'm adding to a plot using
> "mtext". I would like to specify the position of the right hand end of the
> text string, relative to the device (in the left-right direction).
> 
> I've been looking at the use of the argument "adj". But this can't be used
> to specify the rightmost point of the text. Neither does it specify exactly
> the centre of the text, so I'm not sure exactly how it works.
> 
> I could hack it and change "adj" accordingly but this is part of a function
> which I need to generalise. So it needs to be the same regardless of the
> length of the added text, or the values on the x-axis.
> 
> Here's a simple example with two versions (the first three lines of each
> version are identical). I would like the right end of the added text to be
> the same distance from the legend in both versions.
> 
> ### v1
> dev.new()
> plot(c(0,1),c(0,1),ylim=c(0,2))
> legend("topright",c("data1","data2"),col=c(1,2),lty=1,bty="n")
> mtext("text",side=3,line=-2,adj=0.8)
> 
> ### v2
> dev.new()
> plot(c(0,1),c(0,1),ylim=c(0,2))
> legend("topright",c("data1","data2"),col=c(1,2),lty=1,bty="n")
> mtext("really long text",side=3,line=-2,adj=0.8)
> 
> 
> Thank you for your help,
> George


It's not clear to me why you are using mtext() rather than text(). The former 
is typically used for placing text in the margins of a plot, hence the 'm' 
prefix. Also, text() has a 'pos' argument which allows you to align text.

Further, legend() returns a list which provides information on the position of 
the legend drawn and the text inside of it. See the Value section of ?legend.

So, something like the following might work for you:

plot(c(0,1),c(0,1),ylim=c(0,2))

POS <- legend("topright",c("data1","data2"),col=c(1,2),lty=1,bty="n")

# See the content of 'POS' from legend():
> POS
$rect
$rect$w
[1] 0.2047638

$rect$h
[1] 0.2511628

$rect$left
[1] 0.8352362

$rect$top
[1] 2.08


$text
$text$x
[1] 0.9477362 0.9477362

$text$y
[1] 1.996279 1.912558


# Now use text(), right aligning the two lines of text so that 
# they are 0.1 to the left of the edge of the legend box.
text(POS$rect$left - 0.1, 1.9, "text", pos = 2)

text(POS$rect$left - 0.1, 2, "really long text", pos = 2)


See ?text.

HTH,

Marc Schwartz

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


Re: [R] How to define a variable in a function that another function uses without using global variables

2012-01-18 Thread Duncan Murdoch

On 18/01/2012 1:51 PM, R. Michael Weylandt wrote:

Consider this example:

power<- function(n){
 function(x) x^n
} # Note that this function returns a function!


One bit of advice that may matter sometime:  you should call force(n) to 
make sure it is evaluated before creating the new function.  Otherwise 
you get embarrassing results like this:


> n <- 3
> cube <- power(n)
> n <- 2
> cube(2)
[1] 4

Due to lazy evaluation, the n isn't evaluated until after it got changed 
to 2.  This version is safe:


power<- function(n){
force(n)
function(x) x^n
} # Note that this function returns a function!


Duncan Murdoch


cube<- power(3)

cube(2) # gives 8

That make sense?

Michael

On Wed, Jan 18, 2012 at 1:30 PM, statguy  wrote:
>  I would like to know if it is possible to make a function that defines a
>  variable in another function without setting that variable globally?
>
>  I would i.e. be able to define a variables value inside a function ("one
>  level above) which another function makes use of, without setting this
>  variable globally.
>
>  I have provided this very simple illustrating example.
>
>  test1=function(x)
>  {
>  x+y
>  }
>  test2=function(y1)
>  {
>  y=y1
>  test1(2,y1)
>  }
>
>  Running the second function results in an error:
>>  test2(1)
>  Error in test1(2) : object 'y' not found
>
>  I see 2 possible solutions to this, but neither of them is preferred in my
>  more complex situation:
>
>  1. Setting y<<-y_1 globally in test2-function
>  2. making test1 a function of both x and y.
>
>  Is there any other way to do this except from the 2 above? I hope someone
>  can help me with this.
>
>  --
>  View this message in context: 
http://r.789695.n4.nabble.com/How-to-define-a-variable-in-a-function-that-another-function-uses-without-using-global-variables-tp4307604p4307604.html
>  Sent from the R help mailing list archive at Nabble.com.
>
>  __
>  R-help@r-project.org mailing list
>  https://stat.ethz.ch/mailman/listinfo/r-help
>  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>  and provide commented, minimal, self-contained, reproducible code.

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


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


[R] Time series questions

2012-01-18 Thread kchkchkch
Hi, I am trying to teach myself some time series analysis.

I have some time series data on GDP, quarterly, from 1947 to 2011.  colnames
are "Year" "Quarter" "GDP" and "GDP.deflator"

The first problem I have is that 4th quarter 2010 is missing--not even NA,
there is no record for Year=2010 and Quarter =4, so instead of 260 rows, I
only have 259.  To solve this, I created a temporary DF with "Year" and
"Quarter" that was complete 

Yr.temp = rep(1947:2011, rep(4,65))
Qtr.temp = rep(1:4, 65)
Temp.df = data.frame(cbind(Yr.temp,Qtr.temp))

and merged the two, so now I have the NA's.

so, my DF is gdpdata with the above four columns, 260 rows.

My first question: what is the difference between
gdp.ts <- ts(gdpdata$GDP, start=1947, end=2011, fr=4)
and
gdp2.ts <- ts(gdpdata$GDP, start=c(1947,1), end=c(2011,4), fr=4)

I get different outputs for time(gdp.ts) and time(gdp2.ts), and neither make
sense.

time(gdp.ts) gives me this:
   Qtr1 Qtr2 Qtr3 Qtr4
1947 1947 1947 1948 1948
1948 1948 1948 1948 1949
1949 1949 1949 1950 1950
snip
2009 2009 2009 2010 2010
2010 2010 2010 2010 2011
2011 2011

time(gdp2.ts) gives me this:

Qtr1 Qtr2 Qtr3 Qtr4
1947 1947 1947 1948 1948
1948 1948 1948 1948 1949
1949 1949 1949 1950 1950
snip
2009 2009 2009 2010 2010
2010 2010 2010 2010 2011
2011 2011 2011 2012 2012

Where did the missing values for 2011 go in gdp.ts?  why are there 5 2010's
in both, and only 2 1947's?
cycle(gdp2) is correct, cycle(gdp1) is not.

My next question is with the NA in there for 2010q4.  All of the (extremely
basic still learning) time series functions I've been learning don't work. 
For example

m <- decompose(gdp2)
returns
Error in na.omit.ts(x) : time series contains internal NAs

I have tried 
removeNA(gdp2)
and I get
Error in na.omit.ts(x, ...) : time series contains internal NAs

I have tried
na.omit(gdp2)
and I get
Error in na.omit.ts(gdp2) : time series contains internal NAs

Any insight you can share with why this is happening, whether putting the
NA's in was a good idea at all (intuitively it seems like a good idea,
because otherwise, I'd be all out of sync with anything after 2010q4), and
good instructional reading on how to handle data like this in time series
(my googlefu seems out of whack), would be extremely welcome.

I do not understand what to do with the NA's.  Remove them?  will my time
series functions work with the missing 2010q4? Not add them in at all?
Thanks in advance.


--
View this message in context: 
http://r.789695.n4.nabble.com/Time-series-questions-tp4307796p4307796.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] Prediciting sports team scores

2012-01-18 Thread kerry1912
In reply to the first comment: it isn't homework and is in fact to do with a
betting system I am investigating  for my own interest. 

--
View this message in context: 
http://r.789695.n4.nabble.com/Prediciting-sports-team-scores-tp4303708p4307787.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 exactly align the right hand side of "mtext" relative to a plot device? Beyond "adj".

2012-01-18 Thread George Shirreff
Hi,

I have a problem with aligning text which I'm adding to a plot using
"mtext". I would like to specify the position of the right hand end of the
text string, relative to the device (in the left-right direction).

I've been looking at the use of the argument "adj". But this can't be used
to specify the rightmost point of the text. Neither does it specify exactly
the centre of the text, so I'm not sure exactly how it works.

I could hack it and change "adj" accordingly but this is part of a function
which I need to generalise. So it needs to be the same regardless of the
length of the added text, or the values on the x-axis.

Here's a simple example with two versions (the first three lines of each
version are identical). I would like the right end of the added text to be
the same distance from the legend in both versions.

### v1
dev.new()
plot(c(0,1),c(0,1),ylim=c(0,2))
legend("topright",c("data1","data2"),col=c(1,2),lty=1,bty="n")
mtext("text",side=3,line=-2,adj=0.8)

### v2
dev.new()
plot(c(0,1),c(0,1),ylim=c(0,2))
legend("topright",c("data1","data2"),col=c(1,2),lty=1,bty="n")
mtext("really long text",side=3,line=-2,adj=0.8)


Thank you for your help,
George

[[alternative HTML version deleted]]

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


Re: [R] R Table

2012-01-18 Thread Ajay Askoolum
Thank you. I used capture.output(); this is fine.




 From: R. Michael Weylandt 

Cc: R General Forum  
Sent: Wednesday, 18 January 2012, 19:44
Subject: Re: [R] R Table

Capture in what file format / device?

If you want a plain text log, sink() or capture.output() probably will
do it. MASS::write.table() might also help.

I believe library(Hmisc) has some functions for converting to LaTeX
tables as well, but I haven't used those myself.

Michael


> Given a table with colnames and rownames, print(mytable) displays the table 
> nicely formatted.
>
> How can I capture all of what is displayed as a character matrix?
> Thanks.
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]

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


Re: [R] R Table

2012-01-18 Thread R. Michael Weylandt
My mistake: MASS::write.matrix() or utils::write.table()

Michael

On Wed, Jan 18, 2012 at 2:44 PM, R. Michael Weylandt
 wrote:
> Capture in what file format / device?
>
> If you want a plain text log, sink() or capture.output() probably will
> do it. MASS::write.table() might also help.
>
> I believe library(Hmisc) has some functions for converting to LaTeX
> tables as well, but I haven't used those myself.
>
> Michael
>
> On Wed, Jan 18, 2012 at 2:41 PM, Ajay Askoolum  wrote:
>> Given a table with colnames and rownames, print(mytable) displays the table 
>> nicely formatted.
>>
>> How can I capture all of what is displayed as a character matrix?
>> Thanks.
>>        [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] R Table

2012-01-18 Thread R. Michael Weylandt
Capture in what file format / device?

If you want a plain text log, sink() or capture.output() probably will
do it. MASS::write.table() might also help.

I believe library(Hmisc) has some functions for converting to LaTeX
tables as well, but I haven't used those myself.

Michael

On Wed, Jan 18, 2012 at 2:41 PM, Ajay Askoolum  wrote:
> Given a table with colnames and rownames, print(mytable) displays the table 
> nicely formatted.
>
> How can I capture all of what is displayed as a character matrix?
> Thanks.
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] R Table

2012-01-18 Thread Ajay Askoolum
Given a table with colnames and rownames, print(mytable) displays the table 
nicely formatted.

How can I capture all of what is displayed as a character matrix?
Thanks.
[[alternative HTML version deleted]]

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


Re: [R] How to define a variable in a function that another function uses without using global variables

2012-01-18 Thread R. Michael Weylandt
To close things out: credit is due to Thomas L rather than Luke T here:

https://stat.ethz.ch/pipermail/r-help/2011-April/275905.html

Michael

On Wed, Jan 18, 2012 at 2:06 PM, R. Michael Weylandt
 wrote:
> And to the OP: note the all-important "y <- NA" that starts off Bill's
> example. That makes a variable "y"  in the local environment so "<<-"
> finds that first before it gets to searching the global environment
> (and possibly assigning there). It's not so important it's an NA just
> that it's initialized.
>
> (There's a great thread where Luke (I think?) talks about how "<<-"
> should really be "super-assignment" rather than "global assignment"
> somewhere in the archives; it explains why this is so important very
> eloquently and was a real eye opener for me on how "<<-" could be
> something other than trouble)
>
> Bill's solution is more flexible/powerful: but if you are setting the
> constant once and plan to forget about it, I think mine will suffice.
>
> Michael
>
> On Wed, Jan 18, 2012 at 1:57 PM, William Dunlap  wrote:
>> Make an environment that the functions share.  One way to do
>> this is with local():
>>
>>> test <- local({ y <- NA
>> +                 f1 <- function(x) x + y
>> +                 f2 <- function(y1) { y <<- y1 ; f1(1) }
>> +                 list(f1=f1, f2=f2) })
>>> test$f2(2^(1:3))
>> [1] 3 5 9
>>
>> (The example you showed must have had a typo in it,
>> as it didn't give the error message you showed.  I
>> assume you typed 'test1(2,y1)' where you meant 'test1(2)'.)
>>
>> Bill Dunlap
>> Spotfire, TIBCO Software
>> wdunlap tibco.com
>>
>>> -Original Message-
>>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
>>> Behalf Of statguy
>>> Sent: Wednesday, January 18, 2012 10:30 AM
>>> To: r-help@r-project.org
>>> Subject: [R] How to define a variable in a function that another function 
>>> uses without using global
>>> variables
>>>
>>> I would like to know if it is possible to make a function that defines a
>>> variable in another function without setting that variable globally?
>>>
>>> I would i.e. be able to define a variables value inside a function ("one
>>> level above) which another function makes use of, without setting this
>>> variable globally.
>>>
>>> I have provided this very simple illustrating example.
>>>
>>> test1=function(x)
>>>       {
>>>       x+y
>>>       }
>>> test2=function(y1)
>>>       {
>>>       y=y1
>>>       test1(2,y1)
>>>       }
>>>
>>> Running the second function results in an error:
>>> > test2(1)
>>> Error in test1(2) : object 'y' not found
>>>
>>> I see 2 possible solutions to this, but neither of them is preferred in my
>>> more complex situation:
>>>
>>> 1. Setting y<<-y_1 globally in test2-function
>>> 2. making test1 a function of both x and y.
>>>
>>> Is there any other way to do this except from the 2 above? I hope someone
>>> can help me with this.
>>>
>>> --
>>> View this message in context: 
>>> http://r.789695.n4.nabble.com/How-to-define-a-variable-in-a-function-
>>> that-another-function-uses-without-using-global-variables-tp4307604p4307604.html
>>> Sent from the R help mailing list archive at Nabble.com.
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 define a variable in a function that another function uses without using global variables

2012-01-18 Thread statguy
Yes, I'm sorry. There was a typo as you discovered. 
Michael's solution worked fine. 
I will anyway take a look at the "local" function as well. Thank you for
your help.

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-define-a-variable-in-a-function-that-another-function-uses-without-using-global-variables-tp4307604p4307728.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How to define a variable in a function that another function uses without using global variables

2012-01-18 Thread R. Michael Weylandt
And to the OP: note the all-important "y <- NA" that starts off Bill's
example. That makes a variable "y"  in the local environment so "<<-"
finds that first before it gets to searching the global environment
(and possibly assigning there). It's not so important it's an NA just
that it's initialized.

(There's a great thread where Luke (I think?) talks about how "<<-"
should really be "super-assignment" rather than "global assignment"
somewhere in the archives; it explains why this is so important very
eloquently and was a real I opener for me on how "<<-" could be
something other than trouble)

Bill's solution is more flexible/powerful: but if you are setting the
constant once and plan to forget about it, I think mine will suffice.

Michael

On Wed, Jan 18, 2012 at 1:57 PM, William Dunlap  wrote:
> Make an environment that the functions share.  One way to do
> this is with local():
>
>> test <- local({ y <- NA
> +                 f1 <- function(x) x + y
> +                 f2 <- function(y1) { y <<- y1 ; f1(1) }
> +                 list(f1=f1, f2=f2) })
>> test$f2(2^(1:3))
> [1] 3 5 9
>
> (The example you showed must have had a typo in it,
> as it didn't give the error message you showed.  I
> assume you typed 'test1(2,y1)' where you meant 'test1(2)'.)
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
>> Behalf Of statguy
>> Sent: Wednesday, January 18, 2012 10:30 AM
>> To: r-help@r-project.org
>> Subject: [R] How to define a variable in a function that another function 
>> uses without using global
>> variables
>>
>> I would like to know if it is possible to make a function that defines a
>> variable in another function without setting that variable globally?
>>
>> I would i.e. be able to define a variables value inside a function ("one
>> level above) which another function makes use of, without setting this
>> variable globally.
>>
>> I have provided this very simple illustrating example.
>>
>> test1=function(x)
>>       {
>>       x+y
>>       }
>> test2=function(y1)
>>       {
>>       y=y1
>>       test1(2,y1)
>>       }
>>
>> Running the second function results in an error:
>> > test2(1)
>> Error in test1(2) : object 'y' not found
>>
>> I see 2 possible solutions to this, but neither of them is preferred in my
>> more complex situation:
>>
>> 1. Setting y<<-y_1 globally in test2-function
>> 2. making test1 a function of both x and y.
>>
>> Is there any other way to do this except from the 2 above? I hope someone
>> can help me with this.
>>
>> --
>> View this message in context: 
>> http://r.789695.n4.nabble.com/How-to-define-a-variable-in-a-function-
>> that-another-function-uses-without-using-global-variables-tp4307604p4307604.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 define a variable in a function that another function uses without using global variables

2012-01-18 Thread statguy
Great! 
That works perfectly sense. Thanks a lot!

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-define-a-variable-in-a-function-that-another-function-uses-without-using-global-variables-tp4307604p4307715.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] pscl package and hurdle model marginal effects

2012-01-18 Thread Achim Zeileis

Travis,

thanks for the follow-up. As the reply got somewhat lengthier and includes 
a worked example, I include the R-help mailing list again. Maybe the reply 
is useful to someone else in the future.


Thanks for the reply. I think you cleared it up, but I would like to 
follow up to be certain. I also may have mixed some terminology in my 
original question. I have been following Greene's econometrics text, but 
I also have your Applied Econometrics with R that I'll reference for 
this question.


Yes, good idea. Let's take the RecreationDemand data, that's simple. And 
before using confusing terminology, let's look at a practical application, 
that's often more illuminating. Let's use the hurdle model for the number 
of recreational boat trips:


## packages and data
library("pscl")
data("RecreationDemand", package = "AER")

## model
m <- hurdle(trips ~ . | quality + income,
  data = RecreationDemand, dist = "negbin")

As you say below, we get a coefficient for "quality" of 0.17 and 1.5 
respectively. The first one means that the _odds_ (not the probabilities) 
of observing a non-zero number of trips increase strongly with quality: 
about 350% per unit of quality = exp(1.5) - 1. This is still not too 
intuitive due to the usage of odds, but we'll get to probabilities later. 
And the 0.17 mean that the expected number of trips in the count component 
increase by 18% = exp(0.17) - 1 per unity of quality.


But we can also make this even easier to interpret by looking at the 
_effects_ (not the marginal effects) of quality for a "typical" individual 
with average income, average costs, etc.


## new data with quality = 0, ..., 5 and "typical" values
## for all other variables
nd <- data.frame(quality = 0:5, ski = "no", userfee = "no",
  income = mean(RecreationDemand$income),
  costC = mean(RecreationDemand$costC),
  costS = mean(RecreationDemand$costS),
  costH = mean(RecreationDemand$costH))

## predicted probability for non-zero trips
nonzero <- 1 - predict(m, newdata = nd, type = "prob")[, 1]
## visualize
plot(0:5, nonzero, type = "b")
## slopes
diff(nonzero)

So we see that if this "typical" individual had a quality rating of zero, 
the probability of taking any trips at all would only be 5%. While for the 
same "typical" individual with quality rating of 5, the probability of 
taking at least one trip would be 99%. Also we see that the influence is 
clearly non-linear and S-shaped. The slope varies between only 3.4 
percentage points to up to 32 percentage points!


Similarly, we can compute the predicted mean from the count component of 
the model (untruncated):


## predicted mean from (untruncated) count component
countmean <- predict(m, newdata = nd, type = "count")
plot(0:5, countmean, type = "b")

This is also not linear, but not as strongly as for the binary part. 
Finally, we can also combine both model parts to the overall response:


## predicted overall mean (combining both model parts)
allmean <- predict(m, newdata = nd, type = "response")
plot(0:5, allmean, type = "b")

which is still rather S-shaped.

These curves are sometimes also referred to as "effects" and I find them 
rather easy to interpret. For each of these curves you can also look at 
the "marginal effects", i.e., the average slope.


So, if we want to look at the marginal effect of "quality" in the binary 
hurdle part, we can use Equation 5.2 from our AER book or equivalently 
Equation 21-10 from Greene's book (5th ed).


## average regressor
x <- c(1, mean(RecreationDemand$quality), mean(RecreationDemand$income))
## coefficients
b <- coef(m, model = "zero")
## linear predictor x'b
xb <- sum(x * b)
## marginal effect
dlogis(xb) * b["quality"]

As the average quality is 1.42, it is not surprising that this slope is 
similar to the diff(nonzero)[2] (i.e., going from quality=1 to quality=2):
an increase of about 32 percentage points. But we have seen above that the 
slope at quality=4 would be very different from this!


With similar arguments you could compute average slopes for the count mean 
or the overall mean. I don't do it here because I find the _effects_ 
computed above much more useful than the _marginal effects_. However, as 
econometricians prefer numbers to graphics, you don't see many effects 
plots in econometric works. Also, Stata computes marginal effects for just 
about everything - no matter whether it is useful or not.


For standard lm and glm as well as multinom and polr objects, John Fox's
"effects" package can also produce very nice effect displays 
automatically. It does not work for hurdle objects, though.


On pages 140 - 141 of your text you run a hurdle model for recreational 
trips. In the count model the coefficient on QUALITY is 0.1717, and in 
the zero hurdle model the coefficient on quality is 1.5029. Let us 
pretend that QUALITY is the only independent variable. It is my 
understanding that neither 0.1717 or 1.5029 are marginal effects, i.e., 
we cannot say a one percent increase in quality 

Re: [R] How to define a variable in a function that another function uses without using global variables

2012-01-18 Thread William Dunlap
Make an environment that the functions share.  One way to do
this is with local():

> test <- local({ y <- NA
+ f1 <- function(x) x + y
+ f2 <- function(y1) { y <<- y1 ; f1(1) }
+ list(f1=f1, f2=f2) })
> test$f2(2^(1:3))
[1] 3 5 9  

(The example you showed must have had a typo in it,
as it didn't give the error message you showed.  I
assume you typed 'test1(2,y1)' where you meant 'test1(2)'.)

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf Of statguy
> Sent: Wednesday, January 18, 2012 10:30 AM
> To: r-help@r-project.org
> Subject: [R] How to define a variable in a function that another function 
> uses without using global
> variables
> 
> I would like to know if it is possible to make a function that defines a
> variable in another function without setting that variable globally?
> 
> I would i.e. be able to define a variables value inside a function ("one
> level above) which another function makes use of, without setting this
> variable globally.
> 
> I have provided this very simple illustrating example.
> 
> test1=function(x)
>   {
>   x+y
>   }
> test2=function(y1)
>   {
>   y=y1
>   test1(2,y1)
>   }
> 
> Running the second function results in an error:
> > test2(1)
> Error in test1(2) : object 'y' not found
> 
> I see 2 possible solutions to this, but neither of them is preferred in my
> more complex situation:
> 
> 1. Setting y<<-y_1 globally in test2-function
> 2. making test1 a function of both x and y.
> 
> Is there any other way to do this except from the 2 above? I hope someone
> can help me with this.
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/How-to-define-a-variable-in-a-function-
> that-another-function-uses-without-using-global-variables-tp4307604p4307604.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] How to define a variable in a function that another function uses without using global variables

2012-01-18 Thread R. Michael Weylandt
Consider this example:

power <- function(n){
function(x) x^n
} # Note that this function returns a function!

cube <- power(3)

cube(2) # gives 8

That make sense?

Michael

On Wed, Jan 18, 2012 at 1:30 PM, statguy  wrote:
> I would like to know if it is possible to make a function that defines a
> variable in another function without setting that variable globally?
>
> I would i.e. be able to define a variables value inside a function ("one
> level above) which another function makes use of, without setting this
> variable globally.
>
> I have provided this very simple illustrating example.
>
> test1=function(x)
>        {
>        x+y
>        }
> test2=function(y1)
>        {
>        y=y1
>        test1(2,y1)
>        }
>
> Running the second function results in an error:
>> test2(1)
> Error in test1(2) : object 'y' not found
>
> I see 2 possible solutions to this, but neither of them is preferred in my
> more complex situation:
>
> 1. Setting y<<-y_1 globally in test2-function
> 2. making test1 a function of both x and y.
>
> Is there any other way to do this except from the 2 above? I hope someone
> can help me with this.
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/How-to-define-a-variable-in-a-function-that-another-function-uses-without-using-global-variables-tp4307604p4307604.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] How to define a variable in a function that another function uses without using global variables

2012-01-18 Thread statguy
I would like to know if it is possible to make a function that defines a
variable in another function without setting that variable globally?

I would i.e. be able to define a variables value inside a function ("one
level above) which another function makes use of, without setting this
variable globally.

I have provided this very simple illustrating example.

test1=function(x)
{
x+y
}
test2=function(y1)
{
y=y1
test1(2,y1)
}

Running the second function results in an error:
> test2(1)
Error in test1(2) : object 'y' not found

I see 2 possible solutions to this, but neither of them is preferred in my
more complex situation:

1. Setting y<<-y_1 globally in test2-function
2. making test1 a function of both x and y.

Is there any other way to do this except from the 2 above? I hope someone
can help me with this.

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-define-a-variable-in-a-function-that-another-function-uses-without-using-global-variables-tp4307604p4307604.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] Table Intersection

2012-01-18 Thread Martin Morgan

On 01/18/2012 07:25 AM, rantree wrote:

I've got two tables

first one(table1):

ID chromstart end

Ex1   2152  180
Ex2   10  2000  2220
Ex3   15  3000   4000

second one ( table2):

chrom  locationname
2 160  Alv
2190   GNN
2100   ARg
10  210   GGG
15 3200 ADSA

  What I have to do is to put name column in table1  when  the location of
the name  is between the start and end and chrom must be the sameit
will be this the result:

ID chromstart end   name
Ex1   2152  180   Alv
Ex2   10  2000  2220 GGG
Ex3   15  3000   4000 ADSA


How can i do this 


Install the Bioconductor package GenomicRanges

  source("http://bioconductor.org/biocLite.R";)
  biocLite("GenomicRanges")

then

library(GenomicRanges)
t1 <- GRanges(c("2", "10", "15"),
  IRanges(c(152, 2000, 3000),
  c(180, 2220, 4000)),
  Id=c("Ex1", "Ex2", "Ex3"))
t2 <- GRanges(c("2", "2", "2", "10", "15"),
  IRanges(c(160, 190, 100, 2010, 3200),
  width=1),
  Name=c("Alv", "GNN", "ARg", "GGG", "ADSA"))
idx <- match(t1, t2)
values(t1)$Name <- values(t2)$Name[idx]

leading to

> t1
GRanges with 3 ranges and 2 elementMetadata values:
  seqnames   ranges strand |  IdName
|  
  [1]2 [ 152,  180]  * | Ex1 Alv
  [2]   10 [2000, 2220]  * | Ex2 GGG
  [3]   15 [3000, 4000]  * | Ex3ADSA
  ---
  seqlengths:
   10 15  2
   NA NA NA
> as.data.frame(t1)
  seqnames start  end width strand  Id Name
12   152  18029  * Ex1  Alv
2   10  2000 2220   221  * Ex2  GGG
3   15  3000 4000  1001  * Ex3 ADSA


and many other sequence-related operations.

Hope that helps,

Martin



--
View this message in context: 
http://r.789695.n4.nabble.com/Table-Intersection-tp4306968p4306968.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.



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

Location: M1-B861
Telephone: 206 667-2793

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


Re: [R] confint function in MASS package for logistic regression analysis

2012-01-18 Thread William Dunlap
Your original data must have looked something like the following:
  sib.data <- data.frame(sib=rep(c(0,1,0,1), c(159,4,162,37)),
 sex=rep(c(0,0,1,1), c(159, 4, 162, 37)))
as that gives the 2x2 table you showed (with 'Response' -> 'sib'):
  > table(sib.data)
 sex
  sib   0   1
0 159 162
1   4  37
With that data we can recreate your results:
  > sib.glm <- glm(sib~sex,family=binomial,data=sib.data)
  > summary(sib.glm)$coefficients
   Estimate Std. Error   z value Pr(>|z|)
  (Intercept) -3.682610  0.5062440 -7.274377 3.480223e-13
  sex  2.205931  0.5380361  4.099969 4.132054e-05

You can get confidence intervals matching SPSS's and
"the usual confidence interval formula" by calling
confint.default (which uses the variance of the coefficient
estimates, vcov(sib.glm), and the asymptotic formula you
gave).
  > confint.default(sib.glm)
 2.5 %97.5 %
  (Intercept) -4.67483 -2.690390
  sex  1.15140  3.260463

I believe special glm method for confint uses
"profile likelihood" to find the confidence intervals.

There are quite a few descriptions of that available.
  > confint(sib.glm)
  Waiting for profiling to be done...
  2.5 %97.5 %
  (Intercept) -4.861153 -2.823206
  sex  1.263976  3.428764

SPSS probably can do the same sort of calculation, as the
following SPSS document describes the algorithm:
http://publib.boulder.ibm.com/infocenter/spssstat/v20r0m0/index.jsp?topic=%2Fcom.ibm.spss.statistics.help%2Falg_genlin_gzlm_est_ci.htm
 

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf Of Jerome Myers
> Sent: Wednesday, January 18, 2012 7:27 AM
> To: r-help@r-project.org
> Subject: [R] confint function in MASS package for logistic regression analysis
> 
> I have the following binary data set:
>  Sex
> Response  0   1
> 0 159 162
> 1   4 37
>   My commands
>   library(MASS)
>  sib.glm=glm(sib~sex,family=binomial,data=sib.data)
> summary(sib.glm)
> The coefficients in the output are
>  Estimate Std. Error z value Pr(>|z|)
>  (Intercept)  -3.6826 0.5062  -7.274 3.48e-13 ***
>   sex   2.2059 0.5380   4.100 4.13e-05 ***
> I have calculated the .95 confidencce interval for sex two ways:
>  (1) confint(sib.glm)   The result is
>  2.5 %97.5 %
> (Intercept) -4.861153 -2.823206
> sex  1.263976  3.428764
> 
> Using the usual confidence interval formula,
>  (2) 2.2059 +/- 1.96*.538 = 1.15142.  3.26038
> The results from (2) are identical to those from SPSS but do not agree
> with those from the confint function.
> 
>  I have reviewed the MASS pdf file and, seeing no solution there,
> have tried to get the Venables & Ripley book from the local college
> libraries but the only copies are out on loan. I suspect there is a
> simple explanation of the discrepancy, perhaps a modification to account
> for pre-asymptotic distribution. Or perhaps I misunderstand the
> application of the confint fuuction in the MASS package. If someone
> knows the explanation, I'd appreciate it.
> 
> --
> Jerome L. Myers
> 
> 
> 
> 
> 
> 
>   [[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] confint function in MASS package for logistic regression analysis

2012-01-18 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Jerome Myers
> Sent: Wednesday, January 18, 2012 7:27 AM
> To: r-help@r-project.org
> Subject: [R] confint function in MASS package for logistic regression
> analysis
> 
> I have the following binary data set:
>  Sex
> Response  0   1
> 0 159 162
> 1   4 37
>   My commands
>   library(MASS)
>  sib.glm=glm(sib~sex,family=binomial,data=sib.data)
> summary(sib.glm)
> The coefficients in the output are
>  Estimate Std. Error z value Pr(>|z|)
>  (Intercept)  -3.6826 0.5062  -7.274 3.48e-13 ***
>   sex   2.2059 0.5380   4.100 4.13e-05 ***
> I have calculated the .95 confidencce interval for sex two ways:
>  (1) confint(sib.glm)   The result is
>  2.5 %97.5 %
> (Intercept) -4.861153 -2.823206
> sex  1.263976  3.428764
> 
> Using the usual confidence interval formula,
>  (2) 2.2059 +/- 1.96*.538 = 1.15142.  3.26038
> The results from (2) are identical to those from SPSS but do not agree
> with those from the confint function.
> 
>  I have reviewed the MASS pdf file and, seeing no solution there,
> have tried to get the Venables & Ripley book from the local college
> libraries but the only copies are out on loan. I suspect there is a
> simple explanation of the discrepancy, perhaps a modification to
> account
> for pre-asymptotic distribution. Or perhaps I misunderstand the
> application of the confint fuuction in the MASS package. If someone
> knows the explanation, I'd appreciate it.
> 
> --
> Jerome L. Myers
> 

Jerome,

I suspect that the difference you are seeing is due to your "usual confidence 
interval formula" being based on asymptotic normal methods, while the 
confint.glm method from MASS uses profile likelihoods.

Dan

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


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


Re: [R] confint function in MASS package for logistic regression analysis

2012-01-18 Thread Prof Brian Ripley
Yes, the results from confint() are much more accurate than yours and 
SPSS's.  (As Bill Venables once said in a similar circumstance: this is 
not the place to report bugs in SPSS.)


Hint: the word 'profile' appears all over the place on the help pages. 
confint() uses profile likelihood methods.  These are particularly 
appropriate[*] for logistic regression, as explained in the book for 
which this is support software, so you will need to get hold of it.


[*] Rather, what you style 'usual' methods are particularly inappropriate.

On 18/01/2012 15:27, Jerome Myers wrote:

I have the following binary data set:
  Sex
Response  0   1
 0 159 162
 1   4 37
   My commands
   library(MASS)
  sib.glm=glm(sib~sex,family=binomial,data=sib.data)
 summary(sib.glm)
The coefficients in the output are
  Estimate Std. Error z value Pr(>|z|)
  (Intercept)  -3.6826 0.5062  -7.274 3.48e-13 ***
   sex   2.2059 0.5380   4.100 4.13e-05 ***
I have calculated the .95 confidencce interval for sex two ways:
  (1) confint(sib.glm)   The result is
  2.5 %97.5 %
(Intercept) -4.861153 -2.823206
sex  1.263976  3.428764

Using the usual confidence interval formula,
  (2) 2.2059 +/- 1.96*.538 = 1.15142.  3.26038
The results from (2) are identical to those from SPSS but do not agree
with those from the confint function.

  I have reviewed the MASS pdf file and, seeing no solution there,
have tried to get the Venables&  Ripley book from the local college
libraries but the only copies are out on loan. I suspect there is a
simple explanation of the discrepancy, perhaps a modification to account
for pre-asymptotic distribution. Or perhaps I misunderstand the
application of the confint fuuction in the MASS package. If someone
knows the explanation, I'd appreciate it.




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

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


Re: [R] confint function in MASS package for logistic regression analysis

2012-01-18 Thread Marc Schwartz
On Jan 18, 2012, at 9:27 AM, Jerome Myers wrote:

> I have the following binary data set:
> Sex
> Response  0   1
>0 159 162
>1   4 37
>  My commands
>  library(MASS)
> sib.glm=glm(sib~sex,family=binomial,data=sib.data)
>summary(sib.glm)
> The coefficients in the output are
> Estimate Std. Error z value Pr(>|z|)
> (Intercept)  -3.6826 0.5062  -7.274 3.48e-13 ***
>  sex   2.2059 0.5380   4.100 4.13e-05 ***
> I have calculated the .95 confidencce interval for sex two ways:
> (1) confint(sib.glm)   The result is
> 2.5 %97.5 %
> (Intercept) -4.861153 -2.823206
> sex  1.263976  3.428764
> 
> Using the usual confidence interval formula,
> (2) 2.2059 +/- 1.96*.538 = 1.15142.  3.26038
> The results from (2) are identical to those from SPSS but do not agree 
> with those from the confint function.
> 
> I have reviewed the MASS pdf file and, seeing no solution there, 
> have tried to get the Venables & Ripley book from the local college 
> libraries but the only copies are out on loan. I suspect there is a 
> simple explanation of the discrepancy, perhaps a modification to account 
> for pre-asymptotic distribution. Or perhaps I misunderstand the 
> application of the confint fuuction in the MASS package. If someone 
> knows the explanation, I'd appreciate it.



The confint.glm() function in V&R's MASS package provides "profile likelihood" 
confidence intervals for better coverage, as compared to the formula you have 
in (2), which presumes a normally distributed parameter estimate (eg. Wald type 
CI's).

If SPSS is using (2) for logistic regression by default, I would have to 
question why, but not being a user, would also have to think that they offer 
alternative methods.

Do a Google search for "profile likelihood confidence interval" which will lead 
you to a number of suitable references on theory.

HTH,

Marc Schwartz

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


Re: [R] GUI

2012-01-18 Thread Michael Schmidt
A couple of points.  I don't know which Linux distro you are using, but in
general I think it best to install R from the terminal using a CRAN mirror
rather than from the Linux distro repository.  The distro repositories are
sometimes not completely up to date, so you will get more current updates
from the CRAN repositories.  You will also need to add your CRAN mirror to
the Linux software source so it will automatically check for updates.
Instructions for all of this are on the Internet.  When you add new
packages, also use the terminal and log on as an administrative user.
Otherwise, your new packages may not install to the secure system area.

In Linux, the default is for R to run as a terminal application, so you
will need a GUI.  I use R Commander and it works nicely.  It is my
understanding that for some of the more complex analyses it may be best to
use the terminal.  I had a little trouble customizing my R Commander,
especially the font sizes.  This was a bug that was fixed within 24 hours
and now all is good.  An easy way to keep custom settings is with a
.Rprofile file in your user area.  You will also probably want to create a
desktop launcher.

GUI compatibility shouldn't be a problem.  Unlike Windows, in Linux the GUI
is layered on top of the OS.  So, if you use a gnome desktop and want to
run a KDE GUI, it is just a matter of downloading the necessary packages
specific to the GUI.  Linux usually analyzes dependencies and will download
what you need.  One exception i ran into was with the rgl package in R
Commander.  However, a thread on the Ubuntu site provided information about
the missing packages and, once they were installed, all worked well.

Hopefully, you shouldn't have any problems with either a gnome or KDE
desktop.  I can't be so sure about the Unity desktop that Ubuntu has
adopted.  I know, for example, that there have been issues with swt/Jface
Java applications on Unity.  That's why I switched to Linux Mint.

Hope that helps.

[[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] examine grouped data lmList

2012-01-18 Thread agent dunham
Dear community, 


I'm trying to examine my grouped data following page 6
http://cran.r-project.org/doc/contrib/Fox-Companion/appendix-mixed-models.pdf. 


I'm trying lmList this way: 

model.list <- lmList(log(v.dep) ~  log(v2) +log(v4) + v3 | v5, subset =
v6=0,  data=data)

and obtain this error message:  In Ops.factor(v4, v4) : | not meaningful for
factors


My original model is originalmodel <- lm(log(v.dep) ~  log(v2) +log(v4) + v3
+ v5+ v6,  data=data)  (The thing is that I don't know how to specify  that
groups are in v5, where to put in the lmList statement |v5)

By the way, following Fox pdf I was trying as well to group my data, as this
example: 

/attach(Bryk)
cat <- sample(unique(school[sector==’Catholic’]), 20)
Cat.20 <- groupedData(mathach ~ ses | school,  data=Bryk[is.element(school,
cat),])
pub <- sample(unique(school[sector==’Public’]), 20)
Pub.20 <- groupedData(mathach ~ ses | school, data=Bryk[is.element(school,
pub),])/

what am I doing wrong?

cat <- sample(unique(data$v5[v6=0,]), 20)

But Error in NextMethod("[") : first argument invalid


Find attached the data I'm working with.  
http://r.789695.n4.nabble.com/file/n4307083/data data 

Thanks in advance,  u...@host.com




--
View this message in context: 
http://r.789695.n4.nabble.com/examine-grouped-data-lmList-tp4307083p4307083.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] XIII GRASS and GFOSS italian Meeting

2012-01-18 Thread francesca bader
Dear all,
we would like to point out the approaching XIII GRASS and 
GFOSS italian Meeting which will take place at the University of Trieste from 
Wednesday, February 15 until Friday, February 17, 2012.
Abstracts can be sent to  gr...@units.it till January 20 while subscriptions 
are open up to February 6, 2012.
All important informations regarding the meeting can be found 
at http://sites.google.com/site/grassts/


Kind Regards,
Dipartimento di Scienze della Vita
Università degli Studi di Trieste
via Weiss 2, 34127 Trieste
tel. 040 5582072, fax. 040 5582011
mail: gr...@units.it
http://sites.google.com/site/grassts/
[[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] Loess smoothing - alpha Parameter

2012-01-18 Thread 8legged
I have thousands of Fst-values (markers) spread across the genome. I would
like to use Loess to visualize and integrate them along the chromosomes.
This makes sense only along the chromosome, since markers (and thus Fst
values) are physically linked when located in close physical proximity. 
The problem arises, because the length of different chromosomes varies (the
longest is 3-4 times as long as the shortest). If I understand correctly,
when I define in loess() "span" (alpha), I define the number of Fst-values
AS FRACTION OF ALL Fst-values that belong to the same chromsome when when
calculating the local estimated value with loess. E.g., when I take a higher
value for "span", a larger percentage of all values will be considered. 
The problem is, that larger chromosomes have more markers and thus more
Fst-values. I therefore expect a bias between large and short chromosomes.
Is this true? - If so, is there an option to define "span" (alpha) dependent
on the number of values?

thanks

--
View this message in context: 
http://r.789695.n4.nabble.com/Loess-smoothing-alpha-Parameter-tp4307000p4307000.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] confint function in MASS package for logistic regression analysis

2012-01-18 Thread Jerome Myers
I have the following binary data set:
 Sex
Response  0   1
0 159 162
1   4 37
  My commands
  library(MASS)
 sib.glm=glm(sib~sex,family=binomial,data=sib.data)
summary(sib.glm)
The coefficients in the output are
 Estimate Std. Error z value Pr(>|z|)
 (Intercept)  -3.6826 0.5062  -7.274 3.48e-13 ***
  sex   2.2059 0.5380   4.100 4.13e-05 ***
I have calculated the .95 confidencce interval for sex two ways:
 (1) confint(sib.glm)   The result is
 2.5 %97.5 %
(Intercept) -4.861153 -2.823206
sex  1.263976  3.428764

Using the usual confidence interval formula,
 (2) 2.2059 +/- 1.96*.538 = 1.15142.  3.26038
The results from (2) are identical to those from SPSS but do not agree 
with those from the confint function.

 I have reviewed the MASS pdf file and, seeing no solution there, 
have tried to get the Venables & Ripley book from the local college 
libraries but the only copies are out on loan. I suspect there is a 
simple explanation of the discrepancy, perhaps a modification to account 
for pre-asymptotic distribution. Or perhaps I misunderstand the 
application of the confint fuuction in the MASS package. If someone 
knows the explanation, I'd appreciate it.

-- 
Jerome L. Myers






[[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] Table Intersection

2012-01-18 Thread rantree
I've got two tables

first one(table1):

ID chromstart end

Ex1   2152  180
Ex2   10  2000  2220
Ex3   15  3000   4000

second one ( table2):

chrom  locationname
2 160  Alv
2190   GNN
2100   ARg
10  210   GGG
15 3200 ADSA

 What I have to do is to put name column in table1  when  the location of
the name  is between the start and end and chrom must be the sameit
will be this the result:

ID chromstart end   name
Ex1   2152  180   Alv
Ex2   10  2000  2220 GGG
Ex3   15  3000   4000 ADSA


How can i do this 

--
View this message in context: 
http://r.789695.n4.nabble.com/Table-Intersection-tp4306968p4306968.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] restricted model estimation

2012-01-18 Thread Ben Bolker
n.vialma  libero.it  libero.it> writes:

> I would like to know how to estimate in R a restricted model. 
> The model would be:
> 
> y=beta*X1+(1-beta)*X2
> 
> so the sum of coefficients must be one. I wonder if there is an option in the 
> lm function that allows to specify that restriction or any other solutions to 
> get the expected results.

  isn't this the same as y=(a)+beta*(X1-X2) ?

 lm(y~I(X1-X2))

 If you really want a zero intercept, put '-1' in the formula

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


Re: [R] R help

2012-01-18 Thread R. Michael Weylandt
I believe there's also an option to get a daily digest of that day's activity.

Michael

On Wed, Jan 18, 2012 at 12:02 PM, Kevin E. Thorpe
 wrote:
> On 01/18/2012 06:53 AM, Catarina Maia wrote:
>>
>> hello!
>>
>> A few days ago I subscribed the R mailing list in order to ask for some
>> help. The thing is that now I am receiving a lot of mails with doubts from
>> other users but i am just a "R begginer" and i will not able to give
>> useful
>> help.  So,  i would like to quit the from the mainling list. I'm so sorry
>> for
>> the inconvenience.
>>
>> best regards,
>>
>> Catarina Maia
>
>
> An alternative to unsubscribing is to disable mail delivery.  This is done
> by signing on to your account (you should have received a confirmation email
> at some point with the link and password you created).  There you will find
> a check box to disable delivery.
>
> The advantage of this approach is you don't need to re-subscribe later if
> you have another question.
>
> As others have said, you can learn many things by reading some of the posts.
>  If volume is too high, you could create filters for you inbox that
> automatically moves them to another folder for reading.  That's what I do
> and it makes managing the volume trivial.
>
>
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
> --
> Kevin E. Thorpe
> Biostatistician/Trialist,  Applied Health Research Centre (AHRC)
> Li Ka Shing Knowledge Institute of St. Michael's
> Assistant Professor, Dalla Lana School of Public Health
> University of Toronto
> email: kevin.tho...@utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] R help

2012-01-18 Thread Kevin E. Thorpe

On 01/18/2012 06:53 AM, Catarina Maia wrote:

hello!

A few days ago I subscribed the R mailing list in order to ask for some
help. The thing is that now I am receiving a lot of mails with doubts from
other users but i am just a "R begginer" and i will not able to give useful
help.  So,  i would like to quit the from the mainling list. I'm so sorry for
the inconvenience.

best regards,

Catarina Maia


An alternative to unsubscribing is to disable mail delivery.  This is 
done by signing on to your account (you should have received a 
confirmation email at some point with the link and password you 
created).  There you will find a check box to disable delivery.


The advantage of this approach is you don't need to re-subscribe later 
if you have another question.


As others have said, you can learn many things by reading some of the 
posts.  If volume is too high, you could create filters for you inbox 
that automatically moves them to another folder for reading.  That's 
what I do and it makes managing the volume trivial.




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




--
Kevin E. Thorpe
Biostatistician/Trialist,  Applied Health Research Centre (AHRC)
Li Ka Shing Knowledge Institute of St. Michael's
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: kevin.tho...@utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016

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

2012-01-18 Thread n.via...@libero.it
Dear all,
I would like to know how to estimate in R a restricted model. 
The model would be:

y=beta*X1+(1-beta)*X2

so the sum of coefficients must be one. I wonder if there is an option in the 
lm function that allows to specify that restriction or any other solutions to 
get the expected results.

Thanks for your attention!

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


Re: [R] GUI

2012-01-18 Thread Milan Bouchet-Valat
Le mercredi 18 janvier 2012 à 16:23 +0100, Poul Kristensen a écrit :
> How differs Rstudio from RKward?
They seem to be quite similar, but their feature seats are somewhat
different. I don't know RStudio enough to tell.

> I am not aware of the frequence of releases in R but I think it should
> be considered
> that using packets from repositories ensures that you get the updates
> automaticallly.
Sure (if available).

> If using RKward you have to use KDE as Linux desktop.
> Rstudio is for Gnome.
What makes you think that? Although RKWard is written in Qt and uses KDE
libraries, I'm using it under GNOME and it works very well. It doesn't
look completely the same as GNOME apps, but that's very reasonable.
RStudio doesn't really use GTK themes either.

So basically, when you're using GNOME, RKWard and RStudio are two good
alternatives that won't look absolutely integrated with the rest of the
desktop, but that work very well.

> BTW:
> I hope my mails goes to the list. In Gmails new interface it looks
> like I am only mailing
> to the last sender!.  :/
It didn't work, but let's say I forward it.




Regards

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


Re: [R] Using Sweave to generate multiple documents

2012-01-18 Thread Ramiro Barrantes
Just an FYI regarding this question.  I found the answer on the DOCSTRIP, it 
allows you to create tags for different sections of your document, thus 
allowing one to generate multiple documents that share code.  You can see an 
article about this in the December 2011 issue of the R Journal, its the 
Lundholm article: http://journal.r-project.org/current.html

From: Michael Friendly [frien...@yorku.ca]
Sent: Monday, January 16, 2012 8:45 PM
To: Ramiro Barrantes
Cc: r-help@r-project.org
Subject: Re: Using Sweave to generate multiple documents

On 1/16/2012 4:20 PM, Ramiro Barrantes wrote:
> Hello,
>
> I tried looking for a Sweave-specific list but didn't find one, nor did I 
> find an answer via google, so will send this question to the general R list.  
> Please feel free to point me in the right direction.
>
> I am using Sweave and would like to have a single .Rnw document that 
> generates 1) a summary report, 2) a full report, 3) slides for a talk.  I 
> think my material lends itself to have it all coming from one master document 
> because a lot of the plots, writings, and calculations are shared, but I 
> would need Sweave to generate separate files with me somehow pointing to what 
> goes where.  Is this possible with Sweave?
>

Following up on Duncan, I think you are making it too hard to insist
that everything comes from a single .Rnw document, which would entail
an awful lot of conditionals at the latex or R level.

On the other hand, if you have large sections of the .Rnw that would be
shared across the summary report, full report or slides, you can always
put them in separate .Rnw files and then have very short master .Rnw
files that input them, as appropriate, using
\SweaveInput{sec1.Rnw}
\SweaveInput{sec2.Rnw}
...

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 using glht with "Tukey" for lme post-hoc comparisons an appropriate substitute to TukeyHSD?

2012-01-18 Thread Anne Aubut

Hello Richard,
Thank you for all of your feedback and for introducing me to the  
interaction_average argument. I realize that it is probably quite  
simple, but after some research, I am still having difficulty  
understanding how the interaction_average argument changes the  
calculation of multiple comparisons.  If you have a 2-way (A-2 levels,  
B-2 levels) ANOVA with a non-significant interaction term, then does  
interaction_average=FALSE mean that you are comparing A1 pooled over  
both levels of B to A2 pooled over both levels of B?  When  
interaction_average=TRUE, does this mean that you are doing the same  
pooling as above, but that you are also subtracting the contribution  
of the interaction term from the levels of A that you are interested  
in comparing?


I am trying to decide if I should be using interaction_average=TRUE  
for post-hoc testing.  Is it always appropriate to use  
interaction_average=TRUE when non-significant interaction terms are  
present in the model, or does it depend on your specific research  
questions?  Alternatively, should you just remove non-significant  
interaction terms from the model?


Thank you,
Anne

Quoting "Richard M. Heiberger" :


Anne,

Thank you for writing back, and for including your data.

I have two things here.  First, I ran an a analysis of your data and have
my observations
on interpretation.  Second, I answer your general question about glht and
TukeyHSD when there are interactions.
I illustrate how to get the same answer from glht with an example from your
data.


## install.packages("HH")  ## if you do not already have it
library(HH)

Active <- read.table(textConnection("
Treatment HabitatpActive
  1G   E 0.18541667
  1G   E 0.0250
  1G   E 0.04208333
  1G   E 0.14847222
  1G   E 0.0806
  1G   E 0.1678
  1G   S 0.0511
  1G   S 0.1908
  1G   S 0.1233
  1G   S 0.3572
  1G   S 0.4375
  1G   S 0.02638889
  1R   E 0.38736111
  1R   E 0.51180556
  1R   E 0.14916667
  1R   E 0.61041667
  1R   E 0.36013889
  1R   E 0.11347222
  1R   S 0.10805556
  1R   S 0.1872
  1R   S 0.27625000
  1R   S 0.25236111
  1R   S 0.18208333
  1R   S 0.16152778
  2G   E 0.25916667
  2G   E 0.3719
  2G   E 0.02263889
  2G   E 0.18402778
  2G   E 0.4575
  2G   E 0.0225
  2G   S 0.02958333
  2G   S 0.10069444
  2G   S 0.12875000
  2G   S 0.1136
  2G   S 0.13680556
  2G   S 0.07875000
  2R   E 0.57513889
  2R   E 0.1289
  2R   E 0.3200
  2R   E 0.55736111
  2R   E 0.7889
  2R   E 0.6506
  2R   S 0.35527778
  2R   S 0.4836
  2R   S 0.2136
  2R   S 0.3528
  2R   S 0.5261
  2R   S 0.29416667
 R+G   E 0.37027778
 R+G   E 0.20263889
 R+G   E 0.0719
 R+G   E 0.49041667
 R+G   E 0.21847222
 R+G   E 0.1356
 R+G   S 0.2086
 R+G   S 0.23986111
 R+G   S 0.02180556
 R+G   S 0.2325
 R+G   S 0.28916667
 R+G   S 0.50208333
"), header=TRUE)
## close.connection()
closeAllConnections()

logitAct <- logit(Active$pActive)
model3 <- aov(logitAct ~ Treatment*Habitat, data=Active)
summary(model3)
summary(glht(model3, focus="Treatment", linfct=mcp(Treatment="Tukey")))
TukeyHSD(model3)
with(Active, table(Treatment, Habitat))

par(omd=c(0, .95, 0, 1))
model3.mmc <- glht.mmc(model3, linfct=mcp(Treatment="Tukey"))
plot(model3.mmc, ry=c(-2.75, 0.25), x.offset=.8)
plot.matchMMC(model3.mmc$mca)

## 1G  1R  2G  2R R+G
R.linear <- c(-1,  0,  -1,  2,  0 )
names(R.linear) <- c('1G', '1R', '2G', '2R', 'R+G')
lmat.R <- orthog.complete(as.matrix(R.linear))
dimnames(lmat.R)[[2]][1] <- "R.linear"

model3.mmc <- glht.mmc(model3, linfct=mcp(Treatment="Tukey"),
focus.lmat=lmat.R)
plot(model3.mmc, ry=c(-2.75, 0.25), x.offset=.8)
plot.matchMMC(model3.mmc$lmat, col.signif="blue")

Active$Treatment <- factor(Active$Treatment, levels=c('1G', '2G', 'R+G',
'1R', '2R'))
contrasts(Active$Treatment) <- lmat.R[c('1G', '2G', 'R+G', '1R', '2R'),]
model3g <- aov(logitAct ~ Treatment*Habitat, data=Active)
summary(model3g, split=list(Treatment=list(R.linear=1, rest=2:4)),
expand.split=FALSE)

position(Active$Habitat) <- c(2, 4)
interaction2wt(logitAct ~ Treatment*Habitat, data=Active)

## from the above tables and graphs, it looks like the only thing
## going on in the data you posted is the linear effect of R.


## On your questions on glht and TukeyHSD.
## Without interactions or covariates they give the same answer.
## With interactions or covariates the default for glht is to give
different answers.
## The output from glht includes a warning

Re: [R] help! kennard-stone algorithm in soil.spec packages does not work for my dataset!!!

2012-01-18 Thread Leonardo Ramirez-Lopez
Hi all

Certainly there are some problems with the "ken.sto" function. In addition
there are some considerations that need to be taken into account before
using this code. For instance, it projects the data onto a principal
component space prior sampling. In this case is necessary to check if a PCA
is really necessary. Second, this function uses the Euclidean distance (ED)
as metric for selecting the samples. By using the ED directly on the PCs,
the PCs with high explained variance will “dominate” the measurements. In
this case is better to standardize the PCs prior ED computation or use the
Mahalanobis distance.
Whatever, I have modified the “ken.sto” code and now seems to be that it
works correctly. If some of you still need it just drop me an e-mail.
Regards, 

Leonardo Ramirez-Lopez, 

Researcher
Georges Lemaître Centre for Earth and Climate Research
Earth and Life Institute
Université Catholique de Louvain,
3 Place Louis Pasteur
1348, Louvain la Neuve
Belgium
e-mail: leonardo.rami...@uclouvain.be

http://www.uclouvain.be/en-teclim.html


Ph.D Researcher
Physical Geography and Soil Science
Institute of Geography
University of Tübingen
Rümelinstr. 19-23
72070 Tübingen
Germany
http://www.geographie.uni-tuebingen.de/ 




--
View this message in context: 
http://r.789695.n4.nabble.com/help-kennard-stone-algorithm-in-soil-spec-packages-does-not-work-for-my-dataset-tp3031344p4306703.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] problems with method ken.sto in package soil.spec: subscript out of bounds

2012-01-18 Thread rl.leonardo
Hi Martin, 

Certainly there are some problems with the "ken.sto" function In
addition there are some considerations that you have to take into account
before using this code. For instance, it projects the data onto a principal
component space prior sampling. In this case you have to a PCA is really
necessary for your data. Second, this function uses the Euclidean distance
(ED) as metric for selecting the samples. By using the ED directly on the
PCs, the PCs with high explained variance will “dominate” the measurements.
In this case is better to standardize the PCs prior ED computation or use
the Mahalanobis distance.
Whatever, I have modified the “ken.sto” code and now seems to be that it
works for your data ;-) . If you still need it just drop me an e-mail.
Regards, 

Leonardo Ramirez-Lopez, 

Researcher
Georges Lemaître Centre for Earth and Climate Research
Earth and Life Institute
Université Catholique de Louvain,
3 Place Louis Pasteur
1348, Louvain la Neuve
Belgium
e-mail: leonardo.rami...@uclouvain.be

http://www.uclouvain.be/en-teclim.html


Ph.D Researcher
Physical Geography and Soil Science
Institute of Geography
University of Tübingen
Rümelinstr. 19-23
72070 Tübingen
Germany
http://www.geographie.uni-tuebingen.de/ 



--
View this message in context: 
http://r.789695.n4.nabble.com/problems-with-method-ken-sto-in-package-soil-spec-subscript-out-of-bounds-tp4288193p4306689.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] Problems with Panel Data estimation

2012-01-18 Thread JBrettas
Hi everybody,

Got some doubts here. I'm kinda desperate for help, so please ask me if
anything isn't clear.

I have a database with this structure (panel data structure):

> head(dados_2)
  Tempo Safra   Data   Resposta Perc_Resg_Acum Alta_Temporada Flexi Promo
1 1 1 200701 0.04223216  0  1 0 0
2 1 2 200702 0.02801536  0 -1 0 0
3 1 3 200703 0.02786171  0  0 0 0
4 1 4 200704 0.02913633  0  0 0 0
5 1 5 200705 0.03953217  0  0 0 0
6 1 6 200706 0.05084010  0  0 0 0
  Promo_Ponto_Frio Parceiros
10 0
20 0
30 0
40 0
50 0
60 0
> 


where I have 25 levels of "Tempo" and 34 for "Safra".

I want to obtain the confidence intervals of the regression coefficients,
and also forecast the "Resposta" variable with prediction intervals.

But then, I've got some problems here:
-When "Tempo" = 1 (the time index), the variable "Perc_Resg_Acum" gets 0.
-I have some databases of the same kind (panel data structure) and some of
then does not have any value on the variable "Promo" in the entire column.

I'm modeling with the funcions pvcm() and lmList() (which are equivalent),
but then, instead of giving 0 as coefficient for variable "promo", the
function removes the entire column of the model and calculates the
estimations. How can I do to consider the columns of zeros on the regression
model and return a null coefficient instead of NA?

To help with my doubts, here is part of my code:

model_within1 <-
pvcm(Resposta~Perc_Resg_Acum+Alta_Temporada+Flexi+Promo+Promo_Ponto_Frio+Parceiros,
data = dados_2, model="within")

model_within2 <-
lmList(Resposta~Perc_Resg_Acum+Alta_Temporada+Flexi+Promo+Promo_Ponto_Frio+Parceiros|Tempo,
data = dados_2)


When I run the first model, I get this:


> model_within1 <-
> pvcm(Resposta~Perc_Resg_Acum+Alta_Temporada+Flexi+Promo+Promo_Ponto_Frio+Parceiros,
> data = dados_2, model="within")
*serie Promo_Ponto_Frio  is constant and has been removed
Error in eval(expr, envir, enclos) : 
  object 'Promo_Ponto_Frio' not found*> 

(Well, I don't want to remove the constant column and then proceed using it)


With the lmList function, I get no error message, but this outputs:

>model_within2

> model_within2
Call:
  Model: Resposta ~ Perc_Resg_Acum + Alta_Temporada + Flexi + Promo +
Promo_Ponto_Frio + Parceiros | Tempo 
   Data: dados_2 

Coefficients:
   (Intercept) Perc_Resg_Acum Alta_Temporada Flexi Promo
1   0.05575606 NA   0.0094899066NANA
2   0.027672650.602756910   0.0097098374NANA
3   0.014930010.216359571   0.0072083199NANA
4   0.017026440.130147260   0.0073664874NANA
5   0.021991620.077860221   0.0072053502NANA
6   0.025746240.049635548   0.0062181048NANA
7   0.026721930.035288194   0.0064811866NANA
8   0.036205460.001001478   0.0056185695  0.0117215422NA
9   0.03834693   -0.007266645   0.0060674586  0.0107572932NA
10  0.03851210   -0.011103720   0.0059166792  0.0099111959NA
11  0.03877860   -0.011788541   0.0052854680  0.0085353595NA
12  0.04213484   -0.017576921   0.0049738941  0.0084101158NA
13  0.04217531   -0.017615294   0.0057095338  0.0094572949NA
14  0.04591170   -0.027457745   0.0052304802  0.0091305518NA
15  0.05575347   -0.047174244   0.0043227892  0.0070854218NA
16  0.06751835   -0.068053502   0.0041113756  0.0035637901NA
17  0.06743575   -0.066419074   0.0035628714  0.0027136668NA
18  0.08494492   -0.092279778   0.0027045102  0.0025033917  0.0056991774
19  0.10540605   -0.122592396   0.0034576115  0.0007773916  0.0043499539
20  0.09374987   -0.102578612   0.0022937536  0.0003246327 -0.0033912104
21  0.09477620   -0.103937511   0.0018046064 -0.0019254150  0.0038385416
22  0.07984309   -0.081880920   0.0031004004  0.0012212949 -0.0001274436
23  0.04209354   -0.027693308   0.0033759713  0.0012759561 -0.0005342256
24  0.022484390.001793878   0.0019126335  0.0016330109 -0.0012942994
25 -0.041247120.093798787  -0.0009151255  0.0026952764  0.0002002742
   Promo_Ponto_Frio Parceiros
1NA  0.0085825438
2NA -0.0040152859
3NA -0.0015317053
4NA -0.0016866579
5NA -0.0014183949
6NA -0.0016753846
7NA -0.0012411159
8NA -0.0016690746
9NA -0.0018987163
10   NA -0.0016922052
11   NA -0.0017404386
12  

Re: [R] breakpoints and nonlinear regression

2012-01-18 Thread crimsonengineer87
Thanks for the comments. Yes, I also had segmented and then I went away from
that. I can't remember. I've tried using it but I get some sort of strange
error. Here's some code ...


pavlu.glm <- glm(Na ~ yield, data=pavludata, family=gaussian)
pavlu.seg <- segmented(pavlu.glm, seg.Z=~yield, psi=1000,
control=seg.control(display=FALSE))

plot.series <- function()
{
plot(pavlu.seg)
plot(pavlu.seg, add=TRUE, linkinv=TRUE, lwd=2, col=2:3, lty=c(1,3))
lines(pavlu.seg, col=2, pch=19, bottom=FALSE, lwd=2)
}

jpeg("pavlu-cuttingsystem-segmented.jpg", width = 1000, height = 700, units
= "px")
plot.series()

## Turn off device driver (to flush output to JPG)
dev.off()

1. I don't think I'm doing my plotting right. I'm just not sure how that
works with segmented.
2. My error is something about an error in do.call(lines) and that the
maximum number of iterations has been reached. Am I missing something with
glm or lm? 

Thanks again.

--
View this message in context: 
http://r.789695.n4.nabble.com/breakpoints-and-nonlinear-regression-tp4303629p4306657.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] Reference for dataset colon (package survival)

2012-01-18 Thread Terry Therneau
It has obviously been a very long time since I wrote that manual page.
I've now updated it with the following which will show up in the next
release.

\note{The study is described in Laurie et al.  A version of the data
  set with less follow-up time is used in the paper by Lin.}
   
\references{
  JA Laurie, CG Moertel, TR Fleming, HS Wieand, JE Leigh, J Rubin,
  GW McCormack, JB Gerstner, JE Krook and J Malliard.  Surgical
  adjuvant therapy of large-bowel carcinoma: An evaluation of
  levamisole and the combination of levamisole and fluorouracil:
  The North Central Cancer Treatment Group and the Mayo Clinic.
  J Clinical Oncology, 7:1447-1456, 1989.

  DY Lin.  Cox regression analysis of multivariate failure time data:
  the marginal approach.  Statistics in Medicine, 13:2233-2247, 1994.
  }

Thanks for the prompt.

Terry Therneau

- begin included message -
Dear R team, dear Prof. Therneau,

library(survival)
data(colon)
?colon

gives me only a very rudimentary source (only a name). Is there a 
possibility to get a reference to the clinical trial these data
are taken from?

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


Re: [R] Reshape with multiple aggregate functions

2012-01-18 Thread David Winsemius


On Jan 18, 2012, at 4:06 AM, pengcafe wrote:

I have a data frame and I would like to reshape it to wide format  
while at
the same time applying different aggregate functions to each column  
AND at

times multiple aggregate functions:

test1 = data.frame(
   id = c(rep('101',8),rep('102',8)),
   phase  = rep(c('D','D','L','L'),4),
   day = rep(c('1','1','1','1','2','2','2','2'),2),
   col1 = c(rep(1,8),rep(2,8)),
   col2 = c(runif(8,min=0,max=1),runif(8,min=0,max=10))
   )

In this example, I would like to end up with 2 rows (for the 2 ids)  
and
different columns for phase-day. Values of col1 should just be  
summed and

for col 2 there should be a column with the mean AND one with standard
deviation for each phase-day combination.

Obviously the real data have much more number of columns therefore I  
guess I

will need to provide a list of functions?


You should do the reshaping part and the aggregation parts separately  
and then merge the two (or three?) results on "id"


--
David Winsemius, MD
West Hartford, CT

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


Re: [R] sresid with lme4

2012-01-18 Thread Ben Bolker
Rense  gmail.com> writes:

> does anyone know how to extract or calculate studentized residuals for mixed
> effects models estimated with the lme4 package?

  I'm not sure.  The influence.ME package has measures of influence
based on leave-one-out (jackknife) fitting, I think, so it might be
adaptable to this task.

  You should probably try asking this question on the r-sig-mixed-models
(@r-project.org) mailing list.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Scoring using cox model: probability of survival before time t

2012-01-18 Thread Terry Therneau
--begin included message ---

Dear Members,
I required to score probability of survival before specified time using
fitted cox model on scoring dataset.
On the training sample data I am able to get the probability of a
survival
before time point(t), but on the scoring dataset, which will have only
predictor information I am facing some issues. It would be great help
for me
if you tell me where am I going wrong!
Here is the sample script!

--

 Your example isn't complete: the error comes from a function
predictProb.coxph() which I have never heard of, and I wrote the
survival library.  I obviously can't comment on why it fails -- you
might want to contact the author of the function.
 
 Using only the survival library (one of the more recent versions), you
need to know the fact that Pr(survival to t) = exp(-expected events by
t), then you can use
predict(fit_coxph, type="expected", newdata=)
where newdata has a time variable that contains the desired time point
for prediction.

  Note, by default the coxph result does not store all of the data
needed to make predicted survivals (it needs to keep the entire X
matrix).  You can override this by adding "model=TRUE" to the original
call.  If you do not, then it needs to look up the orginal data set to
do the prediction.  

Terry Therneau

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


Re: [R] Reshape with multiple aggregation functions

2012-01-18 Thread Jean V Adams
dimitris fekas wrote on 01/18/2012 03:21:44 AM:

> I have a data frame and I would like to reshape it to wide format 
> while at the same time applying different aggregate functions to 
> each column AND at times multiple aggregate functions: 
>   
> test1 = data.frame( 
> id = c(rep('101',8),rep('102',8)), 
> phase  = rep(c('D','D','L','L'),4), 
> day = rep(c('1','1','1','1','2','2','2','2'),2), 
> col1 = c(rep(1,8),rep(2,8)), 
> col2 = c(runif(8,min=0,max=1),runif(8,min=0,max=10)) 
> ) 
> 
> In this example, I would like to end up with 2 rows (for the 2 ids) 
> and different columns for phase-day. Values of col1 
> should just be summed and for col 2 there should be a column with the 
> mean AND one with standard deviation for each phase-day combination. 
> 
> Obviously the real data have much more number of columns therefore I
> guess I will need to provide a list of functions? 
> 
> Thank you in advance! 


It's not clear to me what you want to end up with.  You seem to want four 
separate columns for each phase-day combination.  But then you describe 
summary statistics for both col1 and col2.  Can you provide an example, 
test2, to make it clear?

Jean

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

2012-01-18 Thread Milan Bouchet-Valat
Le mercredi 18 janvier 2012 à 06:11 -0800, Scott Raynaud a écrit :
> I'm setting up a Linux box to run R.  I ususally run in a Windows
> envrionment but after 
> reading the docs I'm not sure what to expect in terms of the front end
> appearance in 
> Linux.  Does it resemble Windows or will I need Rkward or R Commander?
Just try it. :-)

You'll need to install a GUI if you want one on Linux. The good news is,
there are plenty of them on Linux too (and I think RKWard is a good
choice there).


Regards

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


Re: [R] An "unsubsettable object" in a mixed model

2012-01-18 Thread Ben Bolker
sj414  medschl.cam.ac.uk> writes:

> R has no problem with a command of the type
>   model<-lme(Y~f(x),random=~x|z)
> but returns that error message when the command becomes something like
>model<-lme(Y~f(X),random=~x|z,correlation=corCompSymm)
> Y is a vector of single observations from 2099 individuals, X is the
> covariate matrix of which x is one column, z is the family numbers; 1-1801.
> It seems to be the addition of dependence which causes the problem.

  Yes, because correlation=corCompSymm is not how you're supposed
to specify the correlations: rather, it should look something like

  model <- lme(Y~a+b*X,random=~x|z,correlation=corCompSymm(form=~1|z))


although I think you might be able to get away with

  model <- lme(Y~a+b*X,random=~x|z,correlation=corCompSymm())

  Two more thoughts:

* as I said before, this might be better suited to the r-sig-mixed-models
list
* finding a copy of Pinheiro and Bates 2000 would definitely be a good
idea if you're going to deal with correlation structures in lme much
more ...

  Ben Bolker

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


Re: [R] Checking dates for entry errors

2012-01-18 Thread Terry Therneau
On 1/11/2012 11:07 PM, Paul Miller wrote:
> Hello Everyone,
>
> I have a question about how best to check dates for entry errors.

It depends on the study.
  1. Simple: use as.Date on the data, and find resultant missing values.
You might have to add a format to the as.Date call: if I use
as.Date("2001-02-29", format="%Y-%m-%d") I get an NA as desired (no Feb
29th that year); without it a message that the function can't guess the
right format.

  2. Better: with data set checks.  Say that I have dates of birth,
study enrollment, study events (lab tests), and termination.
Age at entry within the study eligibity criteria
All study events happen between erollment and termination
Termination after enrollment
etc

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


Re: [R] bayesian mixed logit

2012-01-18 Thread Ben Bolker
Carlo F  uea.ac.uk> writes:

> I am tryin on simulated data, say 300 repondents, 8 choice per person, only
> 2 random parameters... so i think it should be well behaved... so I am
> probably doing a mistake! 
> 
> Thank for poiting out the MCMCglmm package, ultimately I need to write my
> own non-linear untility function, so I do not think I can use standard
> packages hence I am writing my own code... you know if MCMCglmm can deal
> with non-linear in parameters utilities,

  It can't.
  But it still might be useful to cross-check with the MCMCglmm results.
You might be surprised at how big a data set you need to get identifiable
random effects ...

   Ben Bolker

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


[R] GUI

2012-01-18 Thread Scott Raynaud
I'm setting up a Linux box to run R.  I ususally run in a Windows envrionment 
but after 
reading the docs I'm not sure what to expect in terms of the front end 
appearance in 
Linux.  Does it resemble Windows or will I need Rkward or R Commander?

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


Re: [R] R help

2012-01-18 Thread John Kane
That's okay.  The mail goes to thousands of people some of whom can help with  
a specfic problem.

It is very useful for some one who is a beginer to read some of the answers. 


You learn a lot by reading about others problems that are similar to yours.


Otherwise do what I do: Just delete any post that is not something that you are 
likely
to need or which is clearly to complicated for a beginner to understand.



- Original Message -
From: Catarina Maia 
To: R-help@r-project.org
Cc: 
Sent: Wednesday, January 18, 2012 6:53:35 AM
Subject: [R] R help

hello!

A few days ago I subscribed the R mailing list in order to ask for some
help. The thing is that now I am receiving a lot of mails with doubts from
other users but i am just a "R begginer" and i will not able to give useful
help.  So,  i would like to quit the from the mainling list. I'm so sorry for
the inconvenience.

best regards,

Catarina Maia

    [[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] R help

2012-01-18 Thread Poul Kristensen
Hello Catarina Maia

I'm a beginner too!

And I ask questions and people are answering very kindly.
>From what I know up til now is that R is a competitor to the
very expensive SAS statistical software. R is free to use and is
developed by professors and Ph.d's.
As of my interest right now is R's interacting with databases like
PostgreSQL(free and opensource) and Oracle(_not_ free) getting
data in and out.
Furthermore I am trying to make R usefull handling Apachelogs.
R does not consume as much machine resources(RAM,CPU) as SAS software as
is faster handling "Big data".

I hope you are encouraged to stay with the list.

Regards
Poul


2012/1/18 Berend Hasselman :
>
> On 18-01-2012, at 12:53, Catarina Maia wrote:
>
>> hello!
>>
>> A few days ago I subscribed the R mailing list in order to ask for some
>> help. The thing is that now I am receiving a lot of mails with doubts from
>> other users but i am just a "R begginer" and i will not able to give useful
>> help.
>
> This is the purpose of a mailing list.
> You don't have to reply to those mails.
> Read and learn.
>
>> So,  i would like to quit the from the mainling list. I'm so sorry for
>> the inconvenience.
>>
>
> Go to the web page mentioned at the bottom of each mail to R-help. 
> https://stat.ethz.ch/mailman/listinfo/r-help
> Is the same page where you subscribed.
>
> Berend
>
>> best regards,
>>
>> Catarina Maia
>>
>>       [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] manipulating data of several columns simultaneously

2012-01-18 Thread Jean V Adams
Nerakg wrote on 01/18/2012 04:48:48 AM:

> Dear all,
> I have a question concerning manipulating data of several columns of a
> dataframe at the same time.
> I manage to do it for one column (with the use of the specific name for 
this
> column). 
> In each columns, I have 60 values. But I should reorganize the values
> (because I created this as an output before and I want to compare it 
with an
> other dataset). I want that the value on row 2 becomes the value of row 
1,
> value 3 value 2 and so on.  The first value would be NA. 


Try this.

# Combine one row of NAs, with the original data frame, minus the last row
results <- rbind(rep(NA, dim(new)[2]), new[-dim(new)[1], ])

new[c(1:3, 58:60), 1:6]

   depth_1 depth_1.5 depth_2 depth_2.5 depth_3 depth_3.5
11 2   3 1   2 3
22 3   4 2   3 4
33 4   5 3   4 5
58  5859  6058  5960
59  5960  6159  6061
60  6061  6260  6162

results[c(1:3, 58:60), 1:6]

   depth_1 depth_1.5 depth_2 depth_2.5 depth_3 depth_3.5
1   NANA  NANA  NANA
21 2   3 1   2 3
32 3   4 2   3 4
58  5758  5957  5859
59  5859  6058  5960
60  5960  6159  6061

Jean


> If I would do this for 1 column (with the name depth_1), I would do it 
like
> this:
> 
> for (t in 2:60)
> {
> results$depth[t]<-new$depth_1[t-1]
> }
> 
> 
> # But in my dataset I have 91 columns and I would like to find a way not
> having to write this for every column?
> # I cannot give my dataset where I?m working on so I created one just 
for
> trying it out and to provide a reproducible example. I created a data 
frame
> ?new? with 26 columns and 60 rows. I named the columns all in a similar 
way
> using ?C <- seq(1,13.5,0.5)?. That means that all my column names are
> structured in the same way: depth_1 ; depth_1.5, depth_2; depth_2.5 and 
so
> on.
> 
> C <- seq(1,13.5,0.5)
> 
> a<-c(1:60)
> b<-c(2:61)
> c<-c(3:62)
> d<-c(1:60)
> e<-c(2:61)
> f<-c(3:62)
> g<-c(1:60)
> h<-c(2:61)
> i<-c(3:62)
> j<-c(1:60)
> k<-c(2:61)
> l<-c(3:62)
> m<-c(1:60)
> n<-c(2:61)
> o<-c(3:62)
> p<-c(1:60)
> q<-c(2:61)
> r<-c(3:62)
> s<-c(1:60)
> t<-c(2:61)
> u<-c(3:62)
> v<-c(1:60)
> w<-c(2:61)
> x<-c(3:62)
> y<-c(1:60)
> z<-c(2:61)
> 
> new<-data.frame(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z)
> names(new)<-c(paste('depth_',C,sep=''))
> 
> #I don't know if I may create a now dataframe that's empty and then 
binding
> my results to it? Or should I create a dataframe with already one column
> with the amount of rows that I will have in my new dataset? #results <-
> data.frame() is what I would use to create an empty
> dataframe but that gives some problems when I want to add other columns
> because the length is different.
> results <- data.frame(time=1:60)
> ### I use n in 2:27 because this needs to be done on column 2 till 
column
> 27, not on column 1
> for (n in 2:27)
> {
> 
> # I don?t know if I should indicate that there should be created an new
> variable with 60 rows? I saw people doing it in a script, but it didn?t 
seem
> necessary in an other script that was similar to it and I made myself?
> # results$newdepth<-(1:60)
> #next line I also don?t know if I should give it. If I did this whole 
thing
> for only 1 column, the firs row was NA without asking for it.
> 
> results$newdepth[1,n]<-NA
> 
> for (t in 2:60)
> {
> results$newdepth[t,n] <- new[t-1,n]
> } 
> results<- cbind(results, results$newdepth)
> }
> 
> names(results) <- c(names(results)[c(1)],paste('newdepth_',C,sep=''))
> #for example:
> results$newdepth_1.5
> 
> I hope someone can help me with this? I hope I gave enough information? 
I
> think there should be an easier manner but I really have no other idea.
> I?m also wondering if it?s possible not using column numbers in a 
function,
> but the name if those are structured in the same way? Eg. 
depth_?followed by
> a number? If you want for example to do something with the columns 
depth_1,
> depth_1.5, depth_2, depth_2.5, depth_3 ? belonging to a dataframe with 
also
> other columns not related with the name depth (Like here, there is also 
the
> column time). I?m hoping there is something useful for that.
> 
> Many thanks,
> Nerak

[[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] manipulating data of several columns simultaneously

2012-01-18 Thread Petr Savicky
On Wed, Jan 18, 2012 at 02:48:48AM -0800, Nerak wrote:
> Dear all,
> I have a question concerning manipulating data of several columns of a
> dataframe at the same time.
> I manage to do it for one column (with the use of the specific name for this
> column). 
> In each columns, I have 60 values. But I should reorganize the values
> (because I created this as an output before and I want to compare it with an
> other dataset). I want that the value on row 2 becomes the value of row 1,
> value 3 value 2 and so on.  The first value would be NA. 
> 
> If I would do this for 1 column (with the name depth_1), I would do it like
> this:
> 
> for (t in 2:60)
> {
> results$depth[t]<-new$depth_1[t-1]
> }
> 
> 
> # But in my dataset I have 91 columns and I would like to find a way not
> having to write this for every column…
> # I cannot give my dataset where I’m working on so I created one just for
> trying it out and to provide a reproducible example. I created a data frame
> ‘new’ with 26 columns and 60 rows. I named the columns all in a similar way
> using ‘C <- seq(1,13.5,0.5)’. That means that all my column names are
> structured in the same way: depth_1 ; depth_1.5, depth_2; depth_2.5 and so
> on.
> 
> C <- seq(1,13.5,0.5)
> 
> a<-c(1:60)
> b<-c(2:61)
> c<-c(3:62)
> d<-c(1:60)
> e<-c(2:61)
> f<-c(3:62)
> g<-c(1:60)
> h<-c(2:61)
> i<-c(3:62)
> j<-c(1:60)
> k<-c(2:61)
> l<-c(3:62)
> m<-c(1:60)
> n<-c(2:61)
> o<-c(3:62)
> p<-c(1:60)
> q<-c(2:61)
> r<-c(3:62)
> s<-c(1:60)
> t<-c(2:61)
> u<-c(3:62)
> v<-c(1:60)
> w<-c(2:61)
> x<-c(3:62)
> y<-c(1:60)
> z<-c(2:61)
> 
> new<-data.frame(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z)
> names(new)<-c(paste('depth_',C,sep=''))
> 

If you want to keep the vector of row names unchanged,
try the following.

  shift <- function(x) { c(NA, x[1:(length(x)-1)]) }
  new1 <- as.data.frame(lapply(new, shift))

  new[c(1:5, 57:60), 1:5]

 depth_1 depth_1.5 depth_2 depth_2.5 depth_3
  11 2   3 1   2
  22 3   4 2   3
  33 4   5 3   4
  44 5   6 4   5
  55 6   7 5   6
  57  5758  5957  58
  58  5859  6058  59
  59  5960  6159  60
  60  6061  6260  61

  new1[c(1:5, 57:60), 1:5]

 depth_1 depth_1.5 depth_2 depth_2.5 depth_3
  1   NANA  NANA  NA
  21 2   3 1   2
  32 3   4 2   3
  43 4   5 3   4
  54 5   6 4   5
  57  5657  5856  57
  58  5758  5957  58
  59  5859  6058  59
  60  5960  6159  60

Petr Savicky.

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


Re: [R] manipulating data of several columns simultaneously

2012-01-18 Thread Gerrit Eichner

Hello, Nerak,

maybe

rbind( NA, head( results, -1))

does what you want (for all columns at once)?

Hth,
Gerrit



On Wed, 18 Jan 2012, Nerak wrote:


Dear all,
I have a question concerning manipulating data of several columns of a 
dataframe at the same time. I manage to do it for one column (with the 
use of the specific name for this column). In each columns, I have 60 
values. But I should reorganize the values (because I created this as an 
output before and I want to compare it with an other dataset). I want 
that the value on row 2 becomes the value of row 1, value 3 value 2 and 
so on.  The first value would be NA.


If I would do this for 1 column (with the name depth_1), I would do it 
like this:


for (t in 2:60)
{
results$depth[t]<-new$depth_1[t-1]
}


[ ... snip ... ]

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


Re: [R] bayesian mixed logit

2012-01-18 Thread Carlo F
Thanks Ben,

I am tryin on simulated data, say 300 repondents, 8 choice per person, only
2 random parameters... so i think it should be well behaved... so I am
probably doing a mistake! :-)

Thank for poiting out the MCMCglmm package, ultimately I need to write my
own non-linear untility function, so I do not think I can use standard
packages hence I am writing my own code... you know if MCMCglmm can deal
with non-linear in parameters utilities,

Cheers,

Caro

--
View this message in context: 
http://r.789695.n4.nabble.com/bayesian-mixed-logit-tp4304327p4306498.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] manipulating data of several columns simultaneously

2012-01-18 Thread Nerak
Dear all,
I have a question concerning manipulating data of several columns of a
dataframe at the same time.
I manage to do it for one column (with the use of the specific name for this
column). 
In each columns, I have 60 values. But I should reorganize the values
(because I created this as an output before and I want to compare it with an
other dataset). I want that the value on row 2 becomes the value of row 1,
value 3 value 2 and so on.  The first value would be NA. 

If I would do this for 1 column (with the name depth_1), I would do it like
this:

for (t in 2:60)
{
results$depth[t]<-new$depth_1[t-1]
}


# But in my dataset I have 91 columns and I would like to find a way not
having to write this for every column…
# I cannot give my dataset where I’m working on so I created one just for
trying it out and to provide a reproducible example. I created a data frame
‘new’ with 26 columns and 60 rows. I named the columns all in a similar way
using ‘C <- seq(1,13.5,0.5)’. That means that all my column names are
structured in the same way: depth_1 ; depth_1.5, depth_2; depth_2.5 and so
on.

C <- seq(1,13.5,0.5)

a<-c(1:60)
b<-c(2:61)
c<-c(3:62)
d<-c(1:60)
e<-c(2:61)
f<-c(3:62)
g<-c(1:60)
h<-c(2:61)
i<-c(3:62)
j<-c(1:60)
k<-c(2:61)
l<-c(3:62)
m<-c(1:60)
n<-c(2:61)
o<-c(3:62)
p<-c(1:60)
q<-c(2:61)
r<-c(3:62)
s<-c(1:60)
t<-c(2:61)
u<-c(3:62)
v<-c(1:60)
w<-c(2:61)
x<-c(3:62)
y<-c(1:60)
z<-c(2:61)

new<-data.frame(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z)
names(new)<-c(paste('depth_',C,sep=''))

#I don't know if I may create a now dataframe that's empty and then binding
my results to it? Or should I create a dataframe with already one column
with the amount of rows that I will have in my new dataset? #results <-
data.frame() is what I would use to create an empty
dataframe but that gives some problems when I want to add other columns
because the length is different.
results <- data.frame(time=1:60)
### I use n in 2:27 because this needs to be done on column 2 till column
27, not on column 1
for (n in 2:27)
{

# I don’t know if I should indicate that there should be created an new
variable with 60 rows? I saw people doing it in a script, but it didn’t seem
necessary in an other script that was similar to it and I made myself…
# results$newdepth<-(1:60)
#next line I also don’t know if I should give it. If I did this whole thing
for only 1 column, the firs row was NA without asking for it.

results$newdepth[1,n]<-NA

for (t in 2:60)
{
results$newdepth[t,n] <- new[t-1,n]
} 
results<- cbind(results, results$newdepth)
}

names(results) <- c(names(results)[c(1)],paste('newdepth_',C,sep=''))
#for example:
results$newdepth_1.5

I hope someone can help me with this… I hope I gave enough information? I
think there should be an easier manner but I really have no other idea.
I’m also wondering if it’s possible not using column numbers in a function,
but the name if those are structured in the same way? Eg. depth_’followed by
a number’ If you want for example to do something with the columns depth_1,
depth_1.5, depth_2, depth_2.5, depth_3 … belonging to a dataframe with also
other columns not related with the name depth (Like here, there is also the
column time). I’m hoping there is something useful for that.

Many thanks,
Nerak


--
View this message in context: 
http://r.789695.n4.nabble.com/manipulating-data-of-several-columns-simultaneously-tp4306278p4306278.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] Reshape with multiple aggregation functions

2012-01-18 Thread pengcafe
Hello, and thanks for your answer, 

I have melted the data already and can reshape it with cast alright, but I
still can find no way to provide a list of aggregate functions per column,
nor multiple aggregate functions for some of them (i.e. mean AND stdev)

--
View this message in context: 
http://r.789695.n4.nabble.com/Re-Reshape-with-multiple-aggregation-functions-tp4306131p4306182.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] quantile type 1 perhaps?

2012-01-18 Thread Francisco

Hello,
I need to analyse some data coming from a questionnaire which have for 
each item a likert scale 1-5. I need to find the lowest scores in the 
distribution, and for this purpose I thought to use the quantile() 
function to identify the participants belonging to the 5% with lowest 
scores (who have a score < than quantile, am I right?).
The problem is: which type of quantile should I calculate? I suppose 
type 1, since it is a discontinuous distribution, but I don't understand 
very well the differences between type 2 and 3.


Thank you,
Francisco

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] computing scores from a factor analysis

2012-01-18 Thread wolfgang
Haj

i try to perform a principal component analysis by using a tetrachoric
correlation matrix as data input

tetra <- tetrachoric (image_na, correct=TRUE)
t_matrix <- tetra$rho
pca.tetra <- principal(t_matrix, nfactors = 10, n.obs = nrow(image_na),
rotate="varimax", scores=TRUE)

the problem i have is to compute the individual factor scores from the pca.
the code runs perfect if i do not ask for the scores

if i ask for the scores i get an error message
"Error in scale(x.matrix): object 'x.matrix' not found"

can somebody help me?

cheers
wolfgang

--
View this message in context: 
http://r.789695.n4.nabble.com/computing-scores-from-a-factor-analysis-tp4306234p4306234.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.


  1   2   >