[R] Lattice: correct use of ltransform3dto3d to plot a surface under a cloud ?

2012-02-04 Thread ilai
Hello list!
I am trying to project the fitted surface to a 3d plot of the data,
similar to figures 13.7 or 6.5 in Deepayan Sarkar's "Lattice,
Multivariate Data Visualization with R", but replace the contour/map
lines with "levelplot". Problem is I can't get the color regions to
line up after the coordinate transformation. Is there a simple
solution my geometry challenged brain missed? It's been driving me
crazy for 2 days now so any help will be greatly appreciated!
I use lattice for all my other figures and would like to stay
consistent, so solutions of the form "package rgl" don't work. Thank
you all in advance.

Here is a minimal (still long) working example of what I mean, and
what I found out so far:

## make data and predicted surf
set.seed(1718)
d <- data.frame(x=runif(60),y=runif(60),g=gl(2,30))
d$z <- with(d,rnorm(60,2*x^as.numeric(g)-y^3))
d$z <- d$z+abs(min(d$z))  # so 'h' goes to the X-Y plane
surf <- by(d,d$g,function(D){
  fit <- lm(z~poly(x,2)+poly(y,2),data=D)
  outer(seq(0,1,l=10),seq(0,1,l=10),function(x,y,...)
predict(fit,data.frame(x=x,y=y)))
})
###
require(lattice)
# Modified code for plot 13.7 [changed: build clines from surf, -.5
for xy coords (why? don't know, works :), 3dscatter not wire]
panel.3d.contour <- function(x, y, z,rot.mat, distance,
zlim.scaled,nlevels=20,...)
{
add.line <- trellis.par.get("add.line")
clines <- contourLines(surf[[packet.number()]],nlevels = nlevels)
for (ll in clines) {
  m <- ltransform3dto3d(rbind(ll$x-.5, ll$y-.5, zlim.scaled[1]),
rot.mat, distance)
  panel.lines(m[1,], m[2,], col = add.line$col, lty = add.line$lty,
  lwd = add.line$lwd)
}
panel.3dscatter(x, y, z, rot.mat, distance, zlim.scaled = zlim.scaled, ...)
  }
cloud(z~x+y|g,data=d,layout=c(2,1), type='h', panel.3d.cloud = panel.3d.contour,
  zoom = 1,screen=list(z= 21,y=0,x=-60),aspect = c(1,1), panel.aspect = 1,
  scales=list(z=list(arrows=F,tck=0)),par.box=list(lty=0),lwd=3)

# This works. But for my data the contours are messy, so I am trying
to use levelplot:
panel.3d.levels <- function(x, y, z,rot.mat, distance, zlim.scaled,...)
{
zz <- surf[[packet.number()]]
n <- nrow(zz)
s <- seq(-.5,.5,l=n)
m <- ltransform3dto3d(rbind(rep(s,n),rep(s,each=n),zlim.scaled[1]),
  rot.mat, distance)
panel.levelplot(m[1,],m[2,],zz,1:n^2,col.regions=heat.colors(20))
panel.3dscatter(x, y, z, rot.mat, distance, zlim.scaled = zlim.scaled, ...)
  }
cloud(z~x+y|g,data=d,layout=c(2,1), type='h', panel.3d.cloud = panel.3d.levels,
  zoom = 1,screen=list(z= 21,y=0,x=-60),aspect = c(1,1), panel.aspect = 1,
  scales=list(z=list(arrows=F,tck=0)),par.box=list(lty=0),lwd=3)

# Unexpected...
# I can use panel.points for centroids and color them in "manually"
but that leaves white space or overlap:
cloud(z~x+y|g,data=d,layout=c(2,1), type='h', par.box=list(lty=0),
lwd=3, scales=list(z=list(arrows=F,tck=0)),
  panel.3d.cloud = function(x, y, z,rot.mat, distance, zlim.scaled,...){
zz <- surf[[packet.number()]]
n <- nrow(zz)
s <- seq(-.5,.5,l=n)
m <- ltransform3dto3d(rbind(rep(s,n),rep(s,each=n),zlim.scaled[1]),
  rot.mat, distance)
lp <- level.colors(zz, at = do.breaks(range(zz), 20),
col.regions = heat.colors(20))
panel.points(m[1,],m[2,],col=lp,pch=18,cex=2.8)
panel.3dscatter(x, y, z, rot.mat, distance, zlim.scaled =
zlim.scaled, ...)
  })

#So I try to "make my own" using the lp for panel.rect, but I get the
same behavior as points for the x0,x1,y0,y1 :
panel.3d.levels <- function(x, y, z,rot.mat, distance, zlim.scaled,...)
{
zz <- surf[[packet.number()]]
n <- nrow(zz)
s <- seq(-.5,.5,l=n)
lp <- level.colors(zz, at = do.breaks(range(zz), 20),
col.regions = heat.colors(20))
cntrds <- expand.grid(s,s)
apply(cntrds,1,function(i){
  xx <- i[1]+c(-.5,.5)/(n-1) ; yy <- i[2]+c(-.5,.5)/(n-1)
   m <- ltransform3dto3d(rbind(xx,yy,zlim.scaled[1]), rot.mat, distance)
   panel.rect(m[1,1],m[2,1],m[1,2],m[2,2])
 })
panel.3dscatter(x, y, z, rot.mat, distance, zlim.scaled = zlim.scaled, ...)
  }
cloud(z~x+y|g,data=d,layout=c(2,1), type='h', panel.3d.cloud = panel.3d.levels,
  zoom = 1,screen=list(z= 21,y=0,x=-60),aspect = c(1,1), panel.aspect = 1,
  scales=list(z=list(arrows=F,tck=0)),par.box=list(lty=0),lwd=3)

# This is as close as I got, but how to get each diagonal of
rectangles "shifted" to cover the space? I thought ltransform3dto3d
will take care of it when I transform every line in the loop. But it
didn't.

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

2012-02-04 Thread dengyu19901102
i want to select June, July and August data from the 3D array (`ssta_sst`,
360*180*362).

the loop works but the output of ssta_winter has the identical values for
`ssta_winter[,,i]`.seen below. I have set it up as an array of (360,180,29).

I think the problem is the variable `temp`, i want to define it as an array
first but i don't know what size it should be (360,180,3) or (360,180,3*29)
and how to keep a loop counter in `temp` when it passes down to finding mean
stage?

   

ssta_winter = array( data=NA, dim = c(360,180,29))
temp = array( data=NA, dim = c(360,180,3))

for (yr in 1982:2010) {
temp <- ssta_sst[,,year_sst==yr & (month_sst>=6 & month_sst<=8)]
for (i in 1:360) {
for (j in 1:180) {
ssta_winter[i,j,] <- mean(temp[i,j,])
}
}
}

> for (i in 1:29){
+ print(ssta_winter[180,166,i])
+ }
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583
[1] 0.583


--
View this message in context: 
http://r.789695.n4.nabble.com/R-Array-data-loop-selection-tp4358282p4358282.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] fractional cointegration

2012-02-04 Thread mamush bukana
Dear folk,
I am stempting to estimate a vector error correction model using a
seemingly fractionally integrated multivariate time series. The
*fracdiff *package
provides tools to estimate degree of fractional integration. But
*fracdiff *can't
help me to:
  1. test equality of two degrees of fractional integration, say d1=d2?
  2. estimate a multivariate cointegrating error correction model, like*
ca.jo *function in* urca* does for standard cointegration.

Can anyone suggest me if there is a way to do these in R please?


Thanks in advance

Mamush.

[[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] unlink: parameter "force" not available in R windows version

2012-02-04 Thread Prof Brian Ripley

On 04/02/2012 18:52, mails wrote:

Hello,

I am not exactly sure but I think the version which is installed on that
windows computer is 2.13.x
So it looks like that the people who developed that function recently
updated it.


Not 'recently': it was a new feature in 2.14.0, released last October 
(and developed over the preceding 6 months).  The 2.14.x series will be 
finalized at the end of this month.



I need to check that on Monday.


See the posting guide: you were asked to update *before* posting.  You 
can also check the NEWS online (the posting guide points you at 
http://cran.r-project.org/src/base/NEWS: the latest sources are at 
https://svn.r-project.org/R/trunk/doc/NEWS.Rd).



Thanks for you answer.





--
View this message in context: 
http://r.789695.n4.nabble.com/unlink-parameter-force-not-available-in-R-windows-version-tp4357464p4357646.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.



--
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] combining data structures

2012-02-04 Thread Pete Brecknock
David

1. The last line of the code should have been ...

Output = as.data.frame(do.call(rbind,nn))

# Output
  Node Connect.up Connect.down
11   NULL 2, 3
22  1 4, 5
33   NULL 2, 3
44  1 4, 5

Apologies for any confusion

2.  I am not familiar with the diagram package or the examples you describe.

Why the desire to create a data frame? Why not just use a list?

HTH

Pete


dkStevens wrote
> 
> Thanks for the reply. Two things - I must have something missing because 
> copying and pasting your example gave me an error
> 
> ... your definitions of nn
> 
>   Output = do.call(as.data.frame(rbind),nn)
> 
> Error in as.data.frame.default(rbind) :
>cannot coerce class '"function"' into a data.frame
> 
> The second is the need, and why I'm not sure this is the best way. This 
> is to customize the flow charting library code from the library 
> 'diagram' to use a node-and-link characterization of a network - think 
> PERT charts or perhaps linking river segments in a water quality model. 
> Each Node will be a, say, circle and has attributes of being connected 
> up to one or more upstream nodes and down to one or more downstream 
> nodes. So the Connect.up column is a vector up upstream connections, 
> usually one but sometimes > one, and likewise Connect.down. There is an 
> accompanying table of links with attributes of which nodes are at each 
> end of a link and other metadata that describe the link (e.g. the length 
> of time required to traverse the link, its name etc. That said, my 
> thought was that the situation was too simple to fire up a full-blown 
> object system beyond what R provides natively. I guess it's like making 
> a data frame that has some 3-d elements.
> 
> 
> 
> On 2/3/2012 9:32 PM, Pete Brecknock wrote:
>> nn=list()
>>
>> nn[[1]] =  list(Node = "1", Connect.up = c(NULL), Connect.down = c(2,3))
>> nn[[2]] =  list(Node = "2", Connect.up = c(1), Connect.down = c(4,5))
>> nn[[3]] =  list(Node = "3", Connect.up = c(NULL), Connect.down = c(2,3))
>> nn[[4]] =  list(Node = "4", Connect.up = c(1), Connect.down = c(4,5))
>>
>> Output = do.call(as.data.frame(rbind),nn)
> 
> -- 
> David K Stevens, P.E., Ph.D., Professor
> Civil and Environmental Engineering
> Utah Water Research Laboratory
> 8200 Old Main Hill
> Logan, UT  84322-8200
> 435 797 3229 - voice
> 435 797 1363 - fax
> david.stevens@
> 
> 
> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> 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.
> 


--
View this message in context: 
http://r.789695.n4.nabble.com/combining-data-structures-tp4356288p4358435.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] Troubles with stemming (tm + Snowball packages) under MacOS

2012-02-04 Thread Julien Velcin
THANK YOU ! Actually, the key is to disable AWT before loading the R  
packages.


At last, it works with just a few warnings.

Julien

On Feb 2, 2012, at 4:36 PM, Zhou Zhou wrote:

The Sys.setenv(NOAWT=TRUE)  code indeed solved my problem which was  
excatly

what Julien described.

The key is you have to deactivate AWT BEFORE loading RWeka/Snowball.  
If I do
so it will fire a few warning messages but that should not affect  
anything.
I am running the lsa package which requires RWeka and Snowball. My R  
version

is 2.14.1, under Mac OS X 10.6.8. My code snippet as below:

dtm<- 
textmatrix 
(ldir 
,minWordLength 
=1,stopwords=stopwords_en,stemming=TRUE,language="english")

Refreshing GOE props...
---Registering Weka Editors---
Trying to add database driver (JDBC): RmiJdbc.RJDriver - Warning,  
not in

CLASSPATH?
Trying to add database driver (JDBC): jdbc.idbDriver - Warning, not in
CLASSPATH?
Trying to add database driver (JDBC): org.gjt.mm.mysql.Driver -  
Warning, not

in CLASSPATH?
Trying to add database driver (JDBC): com.mckoi.JDBCDriver -  
Warning, not in

CLASSPATH?
Trying to add database driver (JDBC): org.hsqldb.jdbcDriver -  
Warning, not

in CLASSPATH?
[KnowledgeFlow] Loading properties and plugins...
[KnowledgeFlow] Initializing KF...



Julien Velcin wrote


I have desactivated AWT (like written in
http://r.789695.n4.nabble.com/Problem-with-Snowball-amp-RWeka-td3402126.html)
with :

Sys.setenv(NOAWT=TRUE)

The command tm_map(reuters, stemDocument) gives the following  
errors :





--
View this message in context: 
http://r.789695.n4.nabble.com/Troubles-with-stemming-tm-Snowball-packages-under-MacOS-tp4292605p4351779.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] problem with windows metafile

2012-02-04 Thread David Winsemius


On Feb 4, 2012, at 5:18 PM, R.newbie wrote:


Hi there!

I have following problem: I created some graphics with  
"win.metafile", which
I wanted to use in a Powerpoint presentation, but when I paste them  
into
Powerpoint the graphics are missing the axes. It looks like the axes  
are cut
off and I was wondering, if somebody know this problem and how to  
solve

this??


Having relatively recently "updated" my Windows and Mac versions of  
Powerpoint, my guess is that the PPT default clipping is what you are  
experiencing and you need to learn how to shrink the full image into  
the display window. Try looking at the file with another viewer. I'll  
be it is all there.




Thanks for your help! :)

win.metafile("example.wmf", width=7, height=5)
plot(1:10)
dev.off()



--
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] strftime - Dates from Excel files

2012-02-04 Thread John Kane
I think you are using the wrong function. See ?strftime

Try
dataset=c("1/2/1978")
strptime(dataset,"%d/%m/%Y")

John Kane
Kingston ON Canada


> -Original Message-
> From: rrast...@gmail.com
> Sent: Fri, 3 Feb 2012 14:34:09 +0100
> To: r-help@r-project.org
> Subject: [R] strftime - Dates from Excel files
> 
> Hi
> 
> I have many excel files were the Date field was not declared as date,
> so the dates look like this: 1/2/1978
> I know that the format is day/month/year
> 
> How can I make R change this to Date format?
> 
> If I use strftime, I get wrong dates:
> 
> dataset=c("1/2/1978")
> 
> strftime(dataset,"%d/%m/%Y")
> "19/02/0001"
> 
> 
> Thanks in advance.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


Send any screenshot to your friends in seconds...
Works in all emails, instant messengers, blogs, forums and social networks.
TRY IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if2 for FREE

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


Re: [R] Having trouble controlling plot() output (e.g., color)

2012-02-04 Thread John Kane
I get the same result.

 I suspect it has something to do with the fact that month is
is a factor.   You would probably be okay if you converted month to a date 
format but I don't have time, at the moment, to test it as I always muck up 
date conversions and take forever to get them right.

I did get a nice graph with colour if I use ggplot2.  Note I changed the 
bs$log_t variable name to logt as ggplot did not like the bs$ 

library(ggplot2)
names(bs_mean) <- c("month", "logt")

p <- ggplot(bs_mean, aes(month, logt))
p <- p + geom_point(colour = "red")
p

John Kane
Kingston ON Canada


> -Original Message-
> From: da...@catwhisker.org
> Sent: Fri, 3 Feb 2012 14:28:35 -0800
> To: r-help@r-project.org
> Subject: [R] Having trouble controlling plot() output (e.g., color)
> 
> I expect that there's something glaringly obvious that I'm overlooking,
> as I'm justr getting back involved in using R after a several-month
> hiatus (from R).  So I welcome clues.
> 
> When I invoke plot(), merely specifying a data.frame with 2 columns,
> specify the plot type ("type") of "p" ("points"), and that I want the
> point to be green ('col = "green"'), sometimes I get the expected
> result; other times I get horizontal black lines instead -- and he
> behavior appears to be consistent for a given data.frame, but I don't
> seem to be able to predict (for a new data.frame) which behavior I'll
> get ... and I'm beginning to wonder about what's left of my sanity. :-}
> 
>> R.Version()
> $platform
> [1] "i386-portbld-freebsd8.2"
> 
> $arch
> [1] "i386"
> 
> $os
> [1] "freebsd8.2"
> 
> $system
> [1] "i386, freebsd8.2"
> 
> $status
> [1] ""
> 
> $major
> [1] "2"
> 
> $minor
> [1] "14.1"
> 
> $year
> [1] "2011"
> 
> $month
> [1] "12"
> 
> $day
> [1] "22"
> 
> $`svn rev`
> [1] "57956"
> 
> $language
> [1] "R"
> 
> $version.string
> [1] "R version 2.14.1 (2011-12-22)"
> 
>> dump("foo", file = "")
> foo <-
> structure(list(X1.5 = 1:5, X6.10 = 6:10), .Names = c("X1.5",
> "X6.10"), row.names = c(NA, -5L), class = "data.frame")
>> dump("bs_mean", file = "")
> bs_mean <-
> structure(list(month = structure(1:13, .Label = c("2011_01",
> "2011_02", "2011_03", "2011_04", "2011_05", "2011_06", "2011_07",
> "2011_08", "2011_09", "2011_10", "2011_11", "2011_12", "2012_01"
> ), class = "factor"), `bs$log_t` = c(1.2026062533015, 1.27747221429551,
> 1.30908704746547, 1.35386015390552, 1.36891795176966, 1.50313159806506,
> 1.41951401509, 1.2575359904, 1.21365151487245, 1.33079015825995,
> 1.50334927085608, 1.39072924382553, 1.44966367892355)), .Names =
> c("month",
> "bs$log_t"), row.names = c(NA, -13L), class = "data.frame")
>> attributes(foo)
> $names
> [1] "X1.5"  "X6.10"
> 
> $row.names
> [1] 1 2 3 4 5
> 
> $class
> [1] "data.frame"
> 
>> attributes(bs_mean)
> $names
> [1] "month""bs$log_t"
> 
> $row.names
>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13
> 
> $class
> [1] "data.frame"
> 
>> plot( bs_mean, type = "p", col = "green" )
>> plot( foo, type = "p", col = "green" )
> 
> 
> The first plot() invocation -- the one that has the data I actually
> care about, of course -- displays a set of 13 horizontal bars, each
> of which appears to be black.  [I actually *like* the horizontal
> bars; I'd like to be able to control the color, though.]
> 
> The second invocation draws a set of 5 green "points" (as I would
> expect).
> 
> How may I plot "bs_mean" in a non-black color?
> 
> Thanks.
> 
> Peace,
> david
> --
> David H. Wolfskillda...@catwhisker.org
> Depriving a girl or boy of an opportunity for education is evil.
> 
> See http://www.catwhisker.org/~david/publickey.gpg for my public key.


Send any screenshot to your friends in seconds...
Works in all emails, instant messengers, blogs, forums and social networks.
TRY IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if2 for FREE

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

2012-02-04 Thread R.newbie
Hi there!

I have following problem: I created some graphics with "win.metafile", which
I wanted to use in a Powerpoint presentation, but when I paste them into
Powerpoint the graphics are missing the axes. It looks like the axes are cut
off and I was wondering, if somebody know this problem and how to solve
this??

Thanks for your help! :)

win.metafile("example.wmf", width=7, height=5) 
plot(1:10)
dev.off()

--
View this message in context: 
http://r.789695.n4.nabble.com/problem-with-windows-metafile-tp4358025p4358025.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 Compare the median to the mean?

2012-02-04 Thread John Kane
This is reallly not a list for homework help.  However I'd guess that you are 
supposed to discuss the mean and median, not assault them with R :)

I probably shouldn't do this. :(

Plot the data and then discuss the mean & median 

John Kane
Kingston ON Canada


> -Original Message-
> From: sonjamackint...@gmail.com
> Sent: Sat, 4 Feb 2012 09:42:24 -0800 (PST)
> To: r-help@r-project.org
> Subject: [R] How to Compare the median to the mean?
> 
> Okay, so I have a homework projecr for R, and we had to input the
> following
> link as some sort of data:
> nb10 <- read.table("http://www.adjoint-functors.net/su/web/314/R/NB10";).
> Afterwards, we have to use
> fivenum(nb10) to find max, min, quantiles, and sd, but I'm okay with
> this.
> The next question is where I'm stuck.  The question is as follows;
> Compare the median (use the quantiles or median(nb10$V1)) to the mean.  I
> found the mean to be 408.8 and the median to be 404.  Can you please
> explain
> to me what I need to put into the program to get an answer and explain
> what
> the answer means?
> 
> Thank You.
> 
> --
> View this message in context:
> http://r.789695.n4.nabble.com/How-to-Compare-the-median-to-the-mean-tp4357520p4357520.html
> Sent from the R help mailing list archive at Nabble.com.


Share photos & screenshots in seconds...
TRY FREE IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if1
Works in all emails, instant messengers, blogs, forums and social networks.

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


Re: [R] sqldf for Very Large Tab Delimited Files

2012-02-04 Thread HC
Thank you Jim for your reply.

I could figure out that readLines works fine until 35,841,335 lines
(records). 

When the next line is read to be read, a window with "R for Windows GUI
front-end has stopped working" message comes, with an option to close
program or checking online for a solution.

The tab-separated .txt file I am working on has 9 columns and about 3.25
billion rows. I suspect that the 35,841,336th line is becoming so very big
that RAM out runs its capacity. Perhaps all tabs that are expected after
each values are missing, making the line so very big, I am not sure.

Is there any way to skip this line with readLines or any other function? I
am only hoping that the data after this bad line is good and I can read them
if I can skip the bad one. 

Thank you.
HC

--
View this message in context: 
http://r.789695.n4.nabble.com/sqldf-for-Very-Large-Tab-Delimited-Files-tp4350555p4357730.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] unlink: parameter "force" not available in R windows version

2012-02-04 Thread mails
Hello,

I am not exactly sure but I think the version which is installed on that
windows computer is 2.13.x
So it looks like that the people who developed that function recently
updated it.
I need to check that on Monday.

Thanks for you answer.





--
View this message in context: 
http://r.789695.n4.nabble.com/unlink-parameter-force-not-available-in-R-windows-version-tp4357464p4357646.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] Optimisation

2012-02-04 Thread Robbie Morrison

> Partha Sinha 
> Wed Feb 1 07:31:08 CET 2012
>
> Can optimisation (simplex etc) be done through R?

The GLPK mixed-integer library has R language bindings.
I am not sure how up-to-date it is though.  Information
is available here:

  http://en.wikibooks.org/wiki/GLPK/R

best wishes
---
Robbie Morrison
PhD student -- policy-oriented energy system simulation
Technical University of Berlin (TU-Berlin), Germany
[from Webmail client]

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


Re: [R] GGPLOT2: Distance of discrete values of from each end of x-axis

2012-02-04 Thread Thomas Schmitt
Sorry group didn't realize this got cross-posted on R-help . . .
thought it didn't make it through. Thanks to Justin Haynes for the
solution below and wanted to pass it along.

With a factor you can add:

scale_x_discrete(expand=c(0, 0))


to plot all the way to the edges:

df <- data.frame(x=factor(letters[1:10]), y=rnorm(100),
group=rep(letters[20:24], each=20))

p <- ggplot(df, aes(x=x, y=y, colour=group)) + geom_line()
c <- scale_x_discrete(expand=c(0, 0)

p
p + c

On Sat, Feb 4, 2012 at 11:18 AM, Thomas Schmitt  wrote:
> Hi Group,
>
> I have been working with the code below. Everything seems to work
> okay, except that the discrete values on the x-axis are far from each
> end of the graph. I've tried several things including changing the
> discrete values and playing with the limits, but can't get it to work.
> I tested this on simulated data and do not have the same problem, so I
> guessing it is how I'm processing the data. I'd appreciate any
> pointers on how to adjust this and/or process the data correctly so it
> does not occur. The data file being imported is a combination of
> continuous, discrete and string variables.
>
> Thanks,
>
> Tom
>
> vicryl.wide <- read.table("C:/vicryl2.csv",
>                          header=TRUE, sep=",", na.strings=" ")
>
> library(reshape2)
> vicryl.long <- melt(vicryl.wide,
>                    id.vars=c("id_finger","sex"),
>                    measure.vars=c("pre_angle_r", "post_angle_r"),
>                    variable.name="pre_post")
>
> names(vicryl.long)[names(vicryl.long)=="value"] <- "angle"
>
> levels(vicryl.long$pre_post)[levels(vicryl.long$pre_post)=="pre_angle_r"] <- 0
> levels(vicryl.long$pre_post)[levels(vicryl.long$pre_post)=="post_angle_r"] <- 
> 2
>
> vicryl.long <- vicryl.long[ order(vicryl.long$id_finger,
> vicryl.long$pre_post), ]
>
> library(ggplot2)
> ggplot(data=vicryl.long, aes(x=pre_post, y=angle, group=id_finger)) +
> geom_line()

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


Re: [R] Problem with xtable- rescaling a table

2012-02-04 Thread Ista Zahn
Hi Aurelien,

You just need to put the \caption outside the scalebox command, like this:

 \documentclass[11pt]{report} 
\usepackage{rotating}
 %\usepackage[counterclockwise]{rotating}
\usepackage{graphics}
\usepackage{float}


\pagestyle{empty}


\begin{document}
\begin{sidewaystable}[ht] 
\centering
\scalebox{0.7}{

% latex table generated in R 2.13.1 by xtable 1.6-0 package
% Wed Feb  1 10:29:25 2012
\begin{tabular}{ccc} 
  \hline
  & V1 & V2 \\  
  \hline
 &  &  \\  
  6.91 & 500.00 & 4.00 \\  
  400.00 &  & 400.00 \\  
   \hline
\end{tabular}
}
\caption{Title}
\end{sidewaystable} 
\end{document}

Best,
Ista



On Wednesday, February 01, 2012 10:37:47 AM Aurélien PHILIPPOT wrote:

Thanks Ista.
Your suggestion works.
When I make the option floating=F, the caption no longer appears in the Tex 
code generated by xtable. If I had \caption {Title} in the code, it does not 
seem to work. 
 \documentclass[11pt]{report} 
\usepackage{rotating}
 %\usepackage[counterclockwise]{rotating}
\usepackage{graphics}
\usepackage{float}


\pagestyle{empty}


\begin{document}
\begin{sidewaystable}[ht] 
\scalebox{0.7}{


% latex table generated in R 2.13.1 by xtable 1.6-0 package
% Wed Feb  1 10:29:25 2012
\begin{tabular}{ccc} 
  \hline
  & V1 & V2 \\  
  \hline
 &  &  \\  
  6.91 & 500.00 & 4.00 \\  
  400.00 &  & 400.00 \\  
   \hline
\end{tabular}
\caption{Title}
}
\end{sidewaystable} 
\end{document}


So, I am faced with a dilemma. If I use the code from my previous email, I 
could have the landscape and the title work, but if I incorporate scalebox in 
Latex it does not work. If I use the floating=F solution, I can rescale and 
landscape, but I have troubles having a caption. That's weird.


Best,
Aurelien






2012/2/1 Ista Zahn 
Hi,

It looks like you need scalebox inside the sidewaystable environment. If you
must use scalebox, one solution is to use floating=FALSE when you call
print.xtable, and insert the table environment directly in LaTeX, like this:

\begin{sidewaystable}[ht]
\scalebox{0.7}{
<>=
print(outfile, include.rownames=F, floating = FALSE)
@
}
\end{sidewaystable}

Alternatively, since the size of the table is determined by the size of the
text in the table, you can just tell LaTeX to use a smaller font, e.g.

<>=
print(outfile, include.rownames=F, floating.environment='sidewaystable', size
= "scriptsize")
@

Best,
Ista


On Tuesday, January 31, 2012 11:41:27 PM Aurélien PHILIPPOT wrote:
> Dear R users,
> I am new to Latex and I am using the R package xtable to generate tables.
> I want to produce a table that is very long.  in the landscape format, but
> I would need to rescale the table so that it fits in the page. xtable
> enables me to have the landscape format, but I cannot rescale it, and there
> seems to be a problem, if I use scalebox in Latex on my output produced
> with stable and the option sidewaystable. Do you know any way to achieve
> this result with xtable or another R package?
>
> Let's look at the following example:
> In R, I use the following code
>
> ##
> outfile<- matrix(nrow=3, ncol=3)
> outfile[2,1]<- 6.912
> outfile[3,1]<- 400
> outfile[2,2]<- 8.9722
> outfile[2,2]<- 500
> outfile[2,3]<- 4.00
> outfile[3,3]<- 400
>
>
>
> library(xtable)
> outfile<- data.frame(outfile)
> colnames(outfile)<- c(" ","V1", "V2")
>
> outfile<- xtable(outfile, caption= "Title", include.rownames=F,
> align=rep("c", 4), digit=2)
> print(outfile, include.rownames=F, floating.environment='sidewaystable')
> 
>
> I was wondering if it is possible to rescale in Latex when  the code was
> generated through xtable.  Indeed, when I run the latex table obtained from
> xtable, and use scale box, it does not work (and the problem comes from
> scalebox, which works otherwise).
>
> \documentclass[11pt]{report}
>
> \usepackage{rotating}
>
>  %\usepackage[counterclockwise]{rotating}
>
> \usepackage{graphics}
>
> \usepackage{float}
>
>
> \pagestyle{empty}
>
>
> \begin{document}
>
> \scalebox{0.70} { %resize
>
>
> % latex table generated in R 2.13.1 by xtable 1.6-0 package
>
> % Tue Jan 31 23:26:10 2012
>
> \begin{sidewaystable}[ht]
>
> \begin{center}
>
> \begin{tabular}{ccc}
>
>   \hline
>
>   & V1 & V2 \\
>
>   \hline
>
>  &  &  \\
>
>   6.91 & 500.00 & 4.00 \\
>
>   400.00 &  & 400.00 \\
>
>\hline
>
> \end{tabular}
>
> \caption{Title}
>
> \end{center}
>
> \end{sidewaystable}
>
>
> }
>
> \end{document}
>
>
>
> Thanks a lot for any advice.
>
>
> Best,
>
> Aurelien
>

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

Re: [R] sqldf for Very Large Tab Delimited Files

2012-02-04 Thread Steve Lianoglou
Hi,

On Fri, Feb 3, 2012 at 1:12 PM, HC  wrote:
> Thank you.
>
> The readLines command is working fine and I am able to read 10^6 lines in
> one go and write them using the write.table command.
>
> Does this readLines command using a block concept to optimize or goes line
> by line?
>
> Steve has mentioned about *nix and split commands. Would there be any speed
> benefit as compared to readLines?

It's easy to test, right? Just give it a shot and see ...

-steve

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

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


Re: [R] Problem with xtable- rescaling a table

2012-02-04 Thread Aurélien PHILIPPOT
Hi Charles,
Thanks for your answer! I am still struggling with two problems with
respect to the example I gave in my message. I have 2 approaches, but each
of them has its limitations, and there are things I cannot do so far with
each of them

1.If I use the following stable command:
print(outfile,floating=F, include.rownames=F, caption="title",
caption.placement="bottom")
then, no title appears in the latex code generated by R, which I copy below:

% latex table generated in R 2.13.1 by xtable 1.6-0 package
% Sat Feb  4 11:56:13 2012
\begin{tabular}{ccc}
  \hline
  & V1 & V2 \\
  \hline
 &  &  \\
  6.91 & 500.00 & 4.00 \\
  400.00 &  & 400.00 \\
   \hline
\end{tabular}

But, I found how to add the title in my latex editor.
If I use the following code, it works fine:

\documentclass[11pt]{report}

\usepackage{rotating}

% \usepackage[counterclockwise]{rotating}

\usepackage{graphics}

\usepackage{float}

\usepackage{capt-of}


\pagestyle{empty}


\begin{document}

%\begin{center}

\begin {sidewaystable}{ % rotate the table

\caption{Table Title}

%\centering

\scalebox{0.70} { %resize


% latex table generated in R 2.13.1 by xtable 1.6-0 package

% Sat Feb  4 11:50:29 2012

\begin{tabular}{ccc}

  \hline

  & V1 & V2 \\

  \hline

 &  &  \\

  6.91 & 500.00 & 4.00 \\

  400.00 &  & 400.00 \\

   \hline

\end{tabular}

\notes: note


}

}

\end{sidewaystable}



%\end{center}

\end{document}


However, if I use this solution, I could not find a way to write a
note below the table. I found a way to write one note but I can't
rotate it and place it below the table


2. The second approach, relies on the following R code:


print(outfile, include.rownames=F,
floating.environment='sidewaystable', floating=T,
caption.placement="bottom")


This solution could be the best, because it incorporates the sideways
command and the title. But then, I was unable to rescale it, when I use
scalebox (see below). It generates error messages.

documentclass[11pt]{report}

\usepackage{rotating}

% \usepackage[counterclockwise]{rotating}

\usepackage{graphics}

\usepackage{float}

\usepackage{capt-of}


\pagestyle{empty}


\begin{document}

\scalebox[0.7]{

% latex table generated in R 2.13.1 by xtable 1.6-0 package

% Sat Feb  4 12:02:09 2012

\begin{sidewaystable}[ht]

\begin{center}

\begin{tabular}{ccc}

  \hline

  & V1 & V2 \\

  \hline

 &  &  \\

  6.91 & 500.00 & 4.00 \\

  400.00 &  & 400.00 \\

   \hline

\end{tabular}

\caption{Title}

\end{center}

\end{sidewaystable}

}

%\end{center}

\end{document}



So, I have 2 approaches, but none of them brings me what I want so far.


Thanks for any suggestion,


Best,

Aurelien


2012/2/3 Charles Roosen 

> Hi,
>
> I'm the maintainer for "xtable" and I'm putting some enhancements in at
> the moment.  I could add in a scalebox argument.
>
> Would this go outside or inside the "center" block?
>
>> > \begin{sidewaystable}[ht]
>> >
>> > \begin{center}
>> >
>> > \begin{tabular}{ccc}
>
> Secondly, what combination of arguments is giving you LaTeX with no
> caption?
>
> Thanks,
> Charlie Roosen
>
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of Aurélien PHILIPPOT
> Sent: 01 February 2012 19:38
> To: Ista Zahn; R-help@r-project.org
> Subject: Re: [R] Problem with xtable- rescaling a table
>
> Thanks Ista.
> Your suggestion works.
> When I make the option floating=F, the caption no longer appears in the
> Tex code generated by xtable. If I had \caption {Title} in the code, it
> does not seem to work.
>  \documentclass[11pt]{report}
>
> \usepackage{rotating}
>
>  %\usepackage[counterclockwise]{rotating}
>
> \usepackage{graphics}
>
> \usepackage{float}
>
>
> \pagestyle{empty}
>
>
> \begin{document}
>
> \begin{sidewaystable}[ht]
>
> \scalebox{0.7}{
>
>
> % latex table generated in R 2.13.1 by xtable 1.6-0 package
>
> % Wed Feb  1 10:29:25 2012
>
> \begin{tabular}{ccc}
>
>  \hline
>
>  & V1 & V2 \\
>
>  \hline
>
>  &  &  \\
>
>  6.91 & 500.00 & 4.00 \\
>
>  400.00 &  & 400.00 \\
>
>   \hline
>
> \end{tabular}
>
> \caption{Title}
>
> }
>
> \end{sidewaystable}
>
> \end{document}
>
>
> So, I am faced with a dilemma. If I use the code from my previous email, I
> could have the landscape and the title work, but if I incorporate scalebox
> in Latex it does not work. If I use the floating=F solution, I can rescale
> and landscape, but I have troubles having a caption. That's weird.
>
>
> Best,
>
> Aurelien
>
>
>
>
> 2012/2/1 Ista Zahn 
>
> Hi,
> >
> > It looks like you need scalebox inside the sidewaystable environment.
> > If you must use scalebox, one solution is to use floating=FALSE when
> > you call print.xtable, and insert the table environment directly in
> > LaTeX, like
> > this:
> >
> > \begin{sidewaystable}[ht]
> > \scalebox{0.7}{
> > <>=
> > print(outfile, include.rownames=F, floating = FALSE) @ }
> > \end{sidewaystable}
> >
> > Alternatively, since the size of the table is determined by the s

Re: [R] least squares solution to linear system

2012-02-04 Thread Berend Hasselman

On 04-02-2012, at 19:14, Alaios wrote:

> Dear all
> I am having a linear system of the form
> A*X=B and I want to find the X by using least squares.
> For example my A is of dimension [205,3] and my B is of dimension[205,1]
> 
>  I am looking for the X matrix which is of the size [3,1]. In the matlab I 
> was doing that by the function
> 
> 
>  X = LSCOV(A,B) returns the ordinary least squares solution to the
> linear system of equations A*X = B, i.e., X is the N-by-1 vector that
> minimizes the sum of squared errors (B - A*X)'*(B - A*X), where A is
> M-by-N, and B is M-by-1
> 
> 
> for example for the matrices
> 
> A =
> 
>  1 2 3
>  4 5 6
>  7 8 9
> 
> K>> B=[1 2 3]
> 
> B =
> 
>  1 2 3
> 
> 
>>> lscov(A,B')
> 
> ans =
> 
>-0.
>  0
> 0.
> 
> How I can get the same in R? I know about the lm function but it looks 
> complicated to me how to insert formula and how to get exactly back only what 
> I need

?qr

Example:

A <- matrix(runif(15),5)
b <- 1:5

solve(qr(A, LAPACK=TRUE), b)

or

lm(b ~ 0 + A)

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.


Re: [R] want to drop levels of table vector & join two vector(appending)

2012-02-04 Thread David Winsemius


On Feb 4, 2012, at 9:07 AM, sagarnikam123 wrote:


is have vector from table stored in s variable

s

[1] R P Y A C P V E S C D R R F S R S A D L T R H I R I
Levels: A C D E F G H I K L M N P Q R S T V Y


If you want to join two factor vectors you need first coerce to  
character vectors, use c() on them and if you want a factor of the  
combined vector, then assign the result of factor() again.




--
View this message in context: 
http://r.789695.n4.nabble.com/want-to-drop-levels-of-table-vector-join-two-vector-appending-tp4356851p4356851.html
Sent from the R help mailing list archive at Nabble.com.

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


David Winsemius, MD
West Hartford, CT

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


[R] least squares solution to linear system

2012-02-04 Thread Alaios
Dear all
I am having a linear system of the form
A*X=B and I want to find the X by using least squares.
For example my A is of dimension [205,3] and my B is of dimension[205,1]

 I am looking for the X matrix which is of the size [3,1]. In the matlab I was 
doing that by the function


 X = LSCOV(A,B) returns the ordinary least squares solution to the
    linear system of equations A*X = B, i.e., X is the N-by-1 vector that
    minimizes the sum of squared errors (B - A*X)'*(B - A*X), where A is
    M-by-N, and B is M-by-1


for example for the matrices

A =

 1 2 3
 4 5 6
 7 8 9

K>> B=[1 2 3]

B =

 1 2 3


>>lscov(A,B')

ans =

   -0.
 0
    0.

How I can get the same in R? I know about the lm function but it looks 
complicated to me how to insert formula and how to get exactly back only what I 
need

Regards
Alex
[[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 Compare the median to the mean?

2012-02-04 Thread chuck.01
I found something a little different:
> median(nb10[,1])
[1] 404
> mean(nb10[,1])
[1] 404.59

compare them 
They are different.   Your sample is not perfectly symmetrical (50% above,
50% below) about the mean (ie. the third standardized moment (skewness) is
not zero).  This is really not a question about R, and this is not a place
to get answers for homework.
Good luck with your studies.   



Ajata Paul wrote
> 
> Okay, so I have a homework projecr for R, and we had to input the
> following link as some sort of data:
> nb10 <- read.table("http://www.adjoint-functors.net/su/web/314/R/NB10";). 
> Afterwards, we have to use 
> fivenum(nb10) to find max, min, quantiles, and sd, but I'm okay with this. 
> The next question is where I'm stuck.  The question is as follows;
> Compare the median (use the quantiles or median(nb10$V1)) to the mean.  I
> found the mean to be 408.8 and the median to be 404.  Can you please
> explain to me what I need to put into the program to get an answer and
> explain what the answer means?
> 
> Thank You.
> 


--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-Compare-the-median-to-the-mean-tp4357520p4357544.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 to Compare the median to the mean?

2012-02-04 Thread Ajata Paul
Okay, so I have a homework projecr for R, and we had to input the following
link as some sort of data:
nb10 <- read.table("http://www.adjoint-functors.net/su/web/314/R/NB10";). 
Afterwards, we have to use 
fivenum(nb10) to find max, min, quantiles, and sd, but I'm okay with this. 
The next question is where I'm stuck.  The question is as follows;
Compare the median (use the quantiles or median(nb10$V1)) to the mean.  I
found the mean to be 408.8 and the median to be 404.  Can you please explain
to me what I need to put into the program to get an answer and explain what
the answer means?

Thank You.  

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-Compare-the-median-to-the-mean-tp4357520p4357520.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] unlink: parameter "force" not available in R windows version

2012-02-04 Thread Uwe Ligges



On 04.02.2012 18:13, mails wrote:

Hello,

I use the R command

unlink(file, recursive = TRUE, force = TRUE)

to delete folders, subfolders and files on Mac OS X.


When I was running my script on a Windows computer I realised that for
unlink there is no option/parameter "force". I do not know why but without
that "force" option R cannot delete the subfolders/files.

What can I do?


Update to a recent version of R.

Uwe Ligges


--
View this message in context: 
http://r.789695.n4.nabble.com/unlink-parameter-force-not-available-in-R-windows-version-tp4357464p4357464.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] 2011 Journal of Statistical Software

2012-02-04 Thread Jan de Leeuw
The Journal of Statistical Software published eight volumes in 2011, five of 
them as special volumes.

V38: Special Volume: Competing Risks and Multi-State Models
V39: Regular Volume
V40: Regular Volume
V41: Special Volume: Statistical Software for State Space Methods
V42: Special Volume: Political Methodology
V43: Regular Volume
V44: Special Volume: Magnetic Resonance Imaging in R
V45: Special Volume: Multiple Imputation

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


Re: [R] 'deparse(substitute'))' then 'assign' in a S4 methods

2012-02-04 Thread William Dunlap
Using substitute() and assign(..., envir=parent.frame()) in
fooBis will lead you into a lot of trouble.  It is nicer to
use a 'replacement function', whose  name ends with '<-',
whose last argument is named 'value', and which returns
the modified first argument.  They are usually paired with
extractor functions.

E.g.,

 > twice <- function(x, value) { 2*x } # 'extractor function'
 > `twice<-` <- function(x, value) { x <- value/2 ; x } # 'replacement function'
 > x <- 1:5
 > twice(x)
 [1]  2  4  6  8 10
 > twice(x)[2] <- 100
 > x
 [1]  1 50  3  4  5

Your example, setting the input to a fixed value, could be
 `fooBis<-` <- function(x, value) { x <- 4 ; x }
You would have to call it as an assignment: whatever is on
the right side would be ignored
 x <- 20
 fooBis(x) <- NULL
 # x should be 4 now

There should not be any problem turning these into S4 generics
in the usual way.


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 cgenolin
> Sent: Saturday, February 04, 2012 2:41 AM
> To: r-help@r-project.org
> Subject: [R] 'deparse(substitute'))' then 'assign' in a S4 methods
> 
> Hi the list,
> 
> I am writing a function in which I need to affect a variable on a higher
> level. My fnction could be:
> 
> ++
> fooBis <- function(x){
>   nameObject <- deparse(substitute(x))
>   print(nameObject)
>   assign(nameObject,4,envir=parent.frame())
> }
> > fooBis(e)
> [1] "e"
> > e
> [1] 4
> -
> 
> (to simplify, this fnction can affect only the number 4. But it does it in
> the parent frame).
> 
> My problem is that I use S4 programming. So the code becomes:
> 
> +
> setGeneric("foo",function(x){standardGeneric("foo")})
> setMethod("foo","ANY",
> function(x){
>   nameObject <- deparse(substitute(x))
>   print(nameObject)
>   assign(nameObject,4,envir=parent.frame())
>}
> )
> ---
> But it does not work since the definition of foo is now:
> 
> +
> > foo
> nonstandardGenericFunction for "foo" defined from package ".GlobalEnv"
> function (x)
> {
> standardGeneric("foo")
> }
> 
> -
> So how can I solve this problem? Is it possible to assign a value to a
> variable on the upper level using S4?
> 
> Sincerely
> Christophe
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/deparse-substitute-then-assign-in-a-S4-
> methods-tp4356748p4356748.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] unlink: parameter "force" not available in R windows version

2012-02-04 Thread mails
Hello,

I use the R command

unlink(file, recursive = TRUE, force = TRUE)

to delete folders, subfolders and files on Mac OS X.


When I was running my script on a Windows computer I realised that for
unlink there is no option/parameter "force". I do not know why but without
that "force" option R cannot delete the subfolders/files. 

What can I do?

--
View this message in context: 
http://r.789695.n4.nabble.com/unlink-parameter-force-not-available-in-R-windows-version-tp4357464p4357464.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] ode() tries to allocate an absurd amount of memory

2012-02-04 Thread Karline Soetaert
Thomas,

It is a limitation of the function you are using. The method "vode" is an 
implicit method, meaning that it has to create and invert a matrix of the size 
= number of variables ^2. In your case, this is a full matrix of 33000 rows and 
columns.
If your ODE is easy to solve, you might try to use method = "adams" or method = 
"ode45", which will select an explicit method, that does not need this huge 
matrix.
If you are trying to solve a PDE, you probably want to use ode.1D or ode.2D or 
ode.3D depending on the dimensionality of your PDE. It is possible to solve 
problems of the order 1e5 variables with these functions.
If it is not a PDE, and it cannot be solved with adams or ode45, then you might 
try method = "lsodes" which will select a sparse solver.


Hope this helps,

Karline

By the way, there exists a mailing list, called R-sig-dynamic-models that deals 
with this type of questions.

Original message:

Date: Fri, 3 Feb 2012 09:33:05 -0500

From: Thomas Brown mailto:thomasbrown8...@gmail.com>>

To: r-help@r-project.org

Subject: [R] ode() tries to allocate an absurd amount of memory

Message-ID:

   
mailto:caf9vq7znr26sxucrdsyem1ietttaj13tmnvdncpfz8t56yj...@mail.gmail.com>>

Content-Type: text/plain



Hi there R-helpers:



I'm having problems with the function ode() found in the package deSolve.

It seems that when my state variables are too numerous (>33000 elements),

the function throws the following error:



Error in vode(y, times, func, parms, ...) :

  cannot allocate memory block of size 137438953456.0 Gb

In addition: Warning message:

In vode(y, times, func, parms, ...) : NAs introduced by coercion



This appears to be case regardless of the computer I use; that is, whether

it's a laptop or server with 24Gb of RAM. Why is ode() trying to allocate

137 billion gigabytes of memory?! (I receive exactly the same error message

whether I have, for example, 34000 or 8 state variables: the amount of

memory trying to be allocated is exactly the same.) I have included a

trivial example below that uses a function that returns a rate of change of

zero for all state variables.



> require(deSolve)

Loading required package: deSolve

> C<-rep(0,34000)

> TestFunc<-function(t,C,para){

+ return(list(rep(0,length(C

+ }

> soln<-ode(y=C,times=seq(0,1,0.1),func=TestFunc,parms=c(0),method="vode")

Error in vode(y, times, func, parms, ...) :

  cannot allocate memory block of size 137438953456.0 Gb

In addition: Warning message:

In vode(y, times, func, parms, ...) : NAs introduced by coercion

>



Am I making a foolish mistake somewhere or is this simply a limitation of

the function?



Thanks in advance!


[[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] GGPLOT2: Distance of discrete values of from each end of x-axis

2012-02-04 Thread Thomas Schmitt
Hi Group,

I have been working with the code below. Everything seems to work
okay, except that the discrete values on the x-axis are far from each
end of the graph. I've tried several things including changing the
discrete values and playing with the limits, but can't get it to work.
I tested this on simulated data and do not have the same problem, so I
guessing it is how I'm processing the data. I'd appreciate any
pointers on how to adjust this and/or process the data correctly so it
does not occur. The data file being imported is a combination of
continuous, discrete and string variables.

Thanks,

Tom

vicryl.wide <- read.table("C:/vicryl2.csv",
  header=TRUE, sep=",", na.strings=" ")

library(reshape2)
vicryl.long <- melt(vicryl.wide,
id.vars=c("id_finger","sex"),
measure.vars=c("pre_angle_r", "post_angle_r"),
variable.name="pre_post")

names(vicryl.long)[names(vicryl.long)=="value"] <- "angle"

levels(vicryl.long$pre_post)[levels(vicryl.long$pre_post)=="pre_angle_r"] <- 0
levels(vicryl.long$pre_post)[levels(vicryl.long$pre_post)=="post_angle_r"] <- 2

vicryl.long <- vicryl.long[ order(vicryl.long$id_finger,
vicryl.long$pre_post), ]

library(ggplot2)
ggplot(data=vicryl.long, aes(x=pre_post, y=angle, group=id_finger)) +
geom_line()

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Major update: paramlink version 0.6-1

2012-02-04 Thread Magnus Dehli Vigeland

Dear all,

I'd like to introduce the paramlink package, offering parametric 
linkage analysis in R, as well as other likelihood-based pedigree 
analyses.
While a rudimentary version of the package has existed for a while, it 
was never properly introduced to this forum. The present version is a 
major update with new and improved functions.


Features:
* Singlepoint LOD scores for simple/complex/inbred pedigrees 
(implementing the Elston-Stewart algorithm). Allows partial genotypes 
(i.e. with one missing allele)
* Multipoint analysis is provided through a wrapper for MERLIN. The 
wrapper creates all necessary files automatically, and makes it easy to 
re-run analysis under different models or with subsets of pedigree 
members/markers.
* Power analysis for linkage (implementing the simulation algorithm of 
SLINK).
* Nice pedigree plots produced by importing the kinship2 package. 
Includes flexible plotting of marker genotypes.

* LOD score plots.
* Reads and writes ped/map/dat/freq/model files in MERLIN format.
* Computation of genotype probability distributions, unconditional or 
conditional on partial marker data:
   - For a single marker, the joint genotype distribution of any number 
of family members.
   - For a single individual, the joint genotype distribution of two 
linked markers.
* Many utility functions for creating/modifying pedigrees. This is 
usually quicker than writing pedigree files from scratch in a text 
editor.


There is a vignette with an introduction to the main features: 
http://cran.r-project.org/web/packages/paramlink/vignettes/paramlink.pdf


Feedback, bug reports and feature requests are most welcome.

Regards,
Magnus

--
Magnus Dehli Vigeland, PhD
Department of Medical Genetics
University of Oslo
Norway

E-mail: magnu...@medisin.uio.no
Phone: +47 22 11 98 79

___
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] newly install old and present R versions

2012-02-04 Thread Uwe Ligges



On 03.02.2012 13:34, Thomas Mang wrote:

Hi,

Moving to a new computer (Windows 7) but for reasons of reproduceability
I would seriously like to also install my present R 2.8.1 along with all
extension packages on that machine as well (that is besides R 2.14.1).

What's the best way of doing so?

My idea is:
Get the setup for 2.8.1 and install it; during install neither select
'save version number in registry' nor 'associate Rdata files' to keep
the registry clean.
Manually Copy the extenxion packages from my present machine to the lib
folder of 2.8.1
That should mean 2.8.1 should run.

Then install 2.14.1 and download most up-to-date versions of packages.
How do i detect if packages were e.g. renamed or merged? Also manually
copying my old packages to the lib dir and then running
update.packages(checkBuilt=TRUE, ask=FALSE)? Will that work under these
circumstances as well?


Yes. But you should not overwrite base packages.



To make things more complicated I am also using Rtools. Is it possible
to have two parallel versions of Rtools? Sure I can install it but I
suppose as it sets some PATH variables only one can actually only be
active at a time. Hence it might be smarter to avoid installing Rtools
for 2.8.1 alltogether, that is live without it (having enough troubles
with running Rtools for one version alongside with MinGW as also the
path to g++ can conflict ...)


You could write simple batch files that set the PATHS you need. E.g. 
wehn moving to the Windows shell, start with


R-2.8.1-settings.bat which contains code that sets the environment 
variables such as PATH appropriately.


Uwe Ligges





thanks,
Thomas

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

2012-02-04 Thread Uwe Ligges



On 04.02.2012 15:36, Christopher Kelvin wrote:


Hello,
i have used the code below to estimate the parameters of weibull distribution 
and i want to obtain the fisher information
by providing the the next code but i receive errors anytime i try to, what do i 
do?
by the way is my replication correct and is it placed at the right position for 
replicating x to obtain the estimates
thank you

n=100
library(survival)
x<-rweibull(n,0.8,1.5)
q<-replicate(1000,x)
z<-function(p){
beta<-p[1]
eta<-p[2]
log1<-(n*log(beta)-n*beta*log(eta)+(beta-1)*sum(log(x))-sum((x/eta)^beta))
return(-log1)
}
zz<-optim(c(0.5,0.5),z)
zz

library(MASS)
out<- nlm(z,zz,x=x hessian = TRUE)


Syntactically wrong: A comma is missing.
Meaningless:  zz is an object returned by optim. You cannot use such an 
object as starting value for the opimization of your z function.


Uwe Ligges


fish<- out$hessian
fish
solve(fish)



Chris Guure
postgraduate researcher/tutor
Institute for Mathematical Research
Universiti Putra Malaysia

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

2012-02-04 Thread Sherlene Enriquez-Savery
I want to run the glm () function for my data but instead of using the
family distributions in R, I need the 4P Burr distribution.

Can some please explain how can I go about doing that. Or  please provide
me with an example.

I‘m new to R.





Eg.

Model1 <- glm(Postwt ~ Prewt + Treat + offset(Prewt),

family = gaussian, data = anorexia)

[[alternative HTML version deleted]]

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


Re: [R] creating R package

2012-02-04 Thread Gabor Grothendieck
On Fri, Feb 3, 2012 at 12:25 PM, ql16717  wrote:
> Hi,
>
> I never acutally made a package before. I have a folder, say called
> "john" that has everything it needs to be in a R package. Some
> instruction says I need Rtools from R mirror site. I installed the
> Rtools, but under DOS, the command "Rcmd" is still not recognized.
>
> Any suggestions? Thanks
> John

Run this R command to find out where Rcmd.exe is on your system:

 list.files("Rcmd.exe", path = R.home(), recursive = TRUE, full = TRUE)

and if its in \x\y\z\Rcmd.exe then:

1. this will run Rcmd.exe

"\x\y\z\Rcmd.exe" ...whatever...

2. or put \x\y\z on your windows path

The above two methods have two deficiencies:  The first one requires
that you enter the path every time you run Rcmd and the second one
requires that you modify your system's path.  Also both procedures
change every time you install a new version of R since the location of
R will normally change.

The following overcomes these disadvantages:

3. or put Rcmd.bat from http://batchfiles.googlecode.com anywhere on
your path (i.e. enter this command
path
into the Windows console and put Rcmd.bat in any of the folders listed)
and then start a new Windows command shell and issue:
Rcmd ...whatever...
That will run Rcmd.bat which will find your R installation from the
registry and then it run Rcmd.exe. If you install a new version of R
then it will automatically pick up the new version of R from the
registry so there will be nothing to change.  Rcmd.bat is a single
self contained windows batch file.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [R] combining data structures

2012-02-04 Thread David Stevens
Thanks for the reply. Two things - I must have something missing because 
copying and pasting your example gave me an error

... your definitions of nn

  Output = do.call(as.data.frame(rbind),nn)

Error in as.data.frame.default(rbind) :
   cannot coerce class '"function"' into a data.frame

The second is the need, and why I'm not sure this is the best way. This 
is to customize the flow charting library code from the library 
'diagram' to use a node-and-link characterization of a network - think 
PERT charts or perhaps linking river segments in a water quality model. 
Each Node will be a, say, circle and has attributes of being connected 
up to one or more upstream nodes and down to one or more downstream 
nodes. So the Connect.up column is a vector up upstream connections, 
usually one but sometimes > one, and likewise Connect.down. There is an 
accompanying table of links with attributes of which nodes are at each 
end of a link and other metadata that describe the link (e.g. the length 
of time required to traverse the link, its name etc. That said, my 
thought was that the situation was too simple to fire up a full-blown 
object system beyond what R provides natively. I guess it's like making 
a data frame that has some 3-d elements.



On 2/3/2012 9:32 PM, Pete Brecknock wrote:
> nn=list()
>
> nn[[1]] =  list(Node = "1", Connect.up = c(NULL), Connect.down = c(2,3))
> nn[[2]] =  list(Node = "2", Connect.up = c(1), Connect.down = c(4,5))
> nn[[3]] =  list(Node = "3", Connect.up = c(NULL), Connect.down = c(2,3))
> nn[[4]] =  list(Node = "4", Connect.up = c(1), Connect.down = c(4,5))
>
> Output = do.call(as.data.frame(rbind),nn)

-- 
David K Stevens, P.E., Ph.D., Professor
Civil and Environmental Engineering
Utah Water Research Laboratory
8200 Old Main Hill
Logan, UT  84322-8200
435 797 3229 - voice
435 797 1363 - fax
david.stev...@usu.edu




[[alternative HTML version deleted]]

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


Re: [R] creating R package

2012-02-04 Thread Uwe Ligges


You do not have the path to the R binary set in your operating systems 
(obviously Windows, although unstated) PATH environment variable. This 
is explained in so many places, including the R Installation and 
Administration manual ...


Uwe Ligges

On 03.02.2012 18:25, ql16717 wrote:

Hi,

I never acutally made a package before. I have a folder, say called
"john" that has everything it needs to be in a R package. Some
instruction says I need Rtools from R mirror site. I installed the
Rtools, but under DOS, the command "Rcmd" is still not recognized.

Any suggestions? Thanks
John

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

2012-02-04 Thread andrija djurovic
Hi.
If I understood you correctly here is one approach to your solution:

> k <- 5
> mat <- diag(1,nrow=k,ncol=k)
> set.seed(10)
> samp <- mat[sample(1:k,3,rep=FALSE),]
> samp
 [,1] [,2] [,3] [,4] [,5]
[1,]00100
[2,]01000
[3,]00010
> #check
> apply(samp,1,sum)
[1] 1 1 1
> apply(samp,2,sum)
[1] 0 1 1 1 0

I hope this helps
Andrija


On Sat, Feb 4, 2012 at 4:27 PM, Alaios  wrote:
> Dear all,
> I would like to create a k,n matrix which that will include
>
>
>
> - k random elements with value 1
> -all rest zeros
>
> -one single "1" in each row
>
> - each column will have maximum one "1"
>
>
> so far I have a so stupid function that with nested while tries to fit k 
> numbers randomly in a row by row fashion, checking also if the c column rule 
> is violated. In that case there is also another loop that will try to find a 
> new solution.
>
> That way it takes ages, as it is natural to complete a matrix of 300,512 as 
> the new ones conflict all the time.
>
> I am trying to find an easy way to make this algorithm way simpler that will 
> help me reduce the time needed.
> I was thinking then if R can help me by shuffling number from 1  to 300 
> randomly, so to avoid the first loop that does that goes row by row.. and 
> then find an easy way to check if the column rule is violated.
>
> Do you think that you can spend some time help me?
>
> Have a nice weekend
>
> Regards
> Alex
>
>        [[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] Making a point-sampling matrix

2012-02-04 Thread Alaios
Dear all,
I would like to create a k,n matrix which that will include 



- k random elements with value 1
-all rest zeros

-one single "1" in each row 

- each column will have maximum one "1"


so far I have a so stupid function that with nested while tries to fit k 
numbers randomly in a row by row fashion, checking also if the c column rule is 
violated. In that case there is also another loop that will try to find a new 
solution.

That way it takes ages, as it is natural to complete a matrix of 300,512 as the 
new ones conflict all the time.

I am trying to find an easy way to make this algorithm way simpler that will 
help me reduce the time needed.
I was thinking then if R can help me by shuffling number from 1  to 300 
randomly, so to avoid the first loop that does that goes row by row.. and then 
find an easy way to check if the column rule is violated.

Do you think that you can spend some time help me?

Have a nice weekend

Regards
Alex

[[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] want to drop levels of table vector & join two vector(appending)

2012-02-04 Thread Petr Savicky
On Sat, Feb 04, 2012 at 06:07:01AM -0800, sagarnikam123 wrote:
> is have vector from table stored in s variable
> > s
>  [1] R P Y A C P V E S C D R R F S R S A D L T R H I R I
> Levels: A C D E F G H I K L M N P Q R S T V Y

Hi.

Is as.character(), what you are looking for?

  as.character(s)

   [1] "R" "P" "Y" "A" "C" "P" "V" "E" "S" "C" "D" "R" "R" "F" "S" "R" "S" "A" 
"D"
  [20] "L" "T" "R" "H" "I" "R" "I"

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.


[R] eliminate rows with all NA values in matrix of special class

2012-02-04 Thread Omphalodes Verna
Dear list!

I have a problem with eliminate rows with all NA values in matrix of special 
class ("my.class"). Belowe is a example:

#class definition
setClass("my.class", representation(ID="character",  years="integer",  
my.mat="matrix"))

data.1 <- new("my.class", ID = c("tA", "tB", "tC"), years = as.integer(c(2000, 
2005, 2010, 2015, 2020)),
my.mat = matrix(c(NA, 1, NA, NA, 4, 3, 1, 5, 6, 2, NA, 5, 1, NA, 3), ncol = 3, 
byrow = TRUE))

data.1

#selection definition
setMethod("[", c("my.class", "numeric", "character"), function(x, i, j, ..., 
drop=TRUE) {
    IDx <- match(j, x@ID)
    if (any(is.na(IDx))) stop("invalid 'j'")
    initialize(x, ID = x@ID[IDx], years = x@years[i],  my.mat = 
x...@my.mat[i, IDx, drop=FALSE])})

setMethod("[", c("my.class", "missing", "character"), function(x, i, j, ..., 
drop=TRUE) {
   
 x[(1:length(x@years)), j, ..., drop=drop]
})

setMethod("[", c("my.class", "missing", "numeric"), function(x, i, j, ..., 
drop=TRUE) {
    x[, x@ID[j], ..., drop=drop]
})

#R output
data.1[, c(1,3)]  # Extract Part of an Object (column 1 & 3)

An object of class “my.class”
Slot "ID":
[1] "tA" "tC"

Slot "years":
[1] 2000 2005 2010 2015 2020

Slot "my.mat":
     [,1] [,2]
[1,]   NA   NA
[2,]   NA    3
[3,]    1    6
[4,]    2    5
[5,]    1    3

But I would like to get like this:

data.1[,c(1,3)]  # Extract Part of an Object (column 1 & 3)

An object of class “my.class”
Slot "ID":
[1] "tA" "tC"

Slot "years": ### without year 2000 because there is no data (all are
 NA)
[1] 2005 2010 2015 2020

Slot "my.mat": ### without first row because there is no data (all are NA)
     [,1] [,2]
[1,]   NA    3
[2,]    1    6
[3,]    2    5
[4,]    1    3

With 'apply' I define which row has all NA values:

which(apply(MATRIX, 1, function(x) all(is.na(x

Please give any suggestions. Thanks a lot, OV
[[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] want to drop levels of table vector & join two vector(appending)

2012-02-04 Thread sagarnikam123
is have vector from table stored in s variable
> s
 [1] R P Y A C P V E S C D R R F S R S A D L T R H I R I
Levels: A C D E F G H I K L M N P Q R S T V Y

--
View this message in context: 
http://r.789695.n4.nabble.com/want-to-drop-levels-of-table-vector-join-two-vector-appending-tp4356851p4356851.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] Simulating from "matrix variate normal distribution"

2012-02-04 Thread Ranjan Maitra
I think this should be easy to write a function doing this.

Assume that Y is matrix normal with mean matrix mu and row and column
dispersion matrices Sigma and Gamma, respectively.

Isn't Y = AZB + mu, where Z is a matrix of independent N(0, 1)'s, A is
the square root matrix of Sigma (the dispersion matrix of the rows) and
B is the square root matrix of Gamma. It should be easy to write this
function in R.

Again, the density should be easy to write. But it is not clear what
you mean by a quantile function (of a matrix variate distribution). A
cdf is going to be a lot harder, but still doable.

Hope this helps!

best wishes,
Ranjan





On Sat, 4 Feb 2012 00:57:45 +0100 Shantanu MULLICK
 wrote:

> Hello everyone
> 
> Is there a function/command to simulate from "matrix variate normal
> distribution" in R.
> 
> A follow up question would be is there a function/command to obtain the
> density, distribution and quantile function of "matrix variate normal
> distribution" in R.
> 
> Wikipedia has a good description of "matrix variate normal distribution"
> which is also alternatively called "matrix normal distribution".
> 
> Thanks a lot !
> 
> Best
> Shantanu
> 
>   [[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] Fisher Imformation

2012-02-04 Thread Christopher Kelvin

Hello,
i have used the code below to estimate the parameters of weibull distribution 
and i want to obtain the fisher information
by providing the the next code but i receive errors anytime i try to, what do i 
do?
by the way is my replication correct and is it placed at the right position for 
replicating x to obtain the estimates
thank you

n=100
library(survival)
x<-rweibull(n,0.8,1.5)
q<-replicate(1000,x)
z<-function(p){
beta<-p[1]
eta<-p[2]
log1<-(n*log(beta)-n*beta*log(eta)+(beta-1)*sum(log(x))-sum((x/eta)^beta))
return(-log1)
}
zz<-optim(c(0.5,0.5),z)
zz

library(MASS)
out <- nlm(z,zz,x=x hessian = TRUE)
fish <- out$hessian
fish
solve(fish)



Chris Guure
postgraduate researcher/tutor
Institute for Mathematical Research
Universiti Putra Malaysia 

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


Re: [R] effect function (effects package)

2012-02-04 Thread John Fox
Dear Eileen,

You apparently misunderstand what the effect() function does; it computes
fitted values and their standard errors under the model (by default in a GLM
on the scale of the response) at specific combinations of values of the
predictors (e.g., letting two interacting predictors range over their
combinations of values while others are held to their means). Details are
provided in the references given in ?effect; see in particular the 2003
Journal of Statistical Software article at
. 

I hope this helps,
 John


John Fox
Senator William McMaster
  Professor of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox



> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Hlavka, Eileen
> Sent: February-04-12 1:56 AM
> To: r-help@r-project.org
> Subject: [R] effect function (effects package)
> 
> Dear all,
> 
> How does the effect() function in the effects package calculate
> effects and standard errors for glm quasipoisson models?  I was using
> effect() to calculate the impact of increasing x to e + epsilon, and
> then finding the expected percent change.  I thought that this effect
> (as a percentage) should be exp(beta*epsilon), where beta is the
> appropriate coefficient from the model, but that's not what I'm
> getting using the effect() output.
> 
> Sorry for the lack of example-it would require toy data etc. and seems
> unnecessary since my question is more conceptual.
> 
> Thanks,
> 
> Eileen
> 
> 
> 
> __
> 
> 
> This email message is for the sole use of the intended
> r...{{dropped:9}}
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Checking for invalid dates: Code works but needs improvement

2012-02-04 Thread Paul Miller
Hi David and Rui,

Sorry to be so slow in replying. Thank you both for pointing out that the 
problem with my code was that I was using comparison operators on mixed data 
types. This is something I'll have to be more careful about in the future.

In an earlier email, David talked about how R can seem uncooperative or even 
"unfair" when you're just starting out. I too have had this experience, but it 
seems less "unfair" each time I use it. This time, I was able to write 
inelegant but functional code to solve my problem. Last time, I wasn't able to 
solve a much simpler problem at all. So I guess that's a kind of progress. 

At this point, I have serviceable code for checking my dates. I can improve 
this when I begin to develop some real skill as an R programmer, but it will do 
nicely for now.

Thanks everyone for your help with this.

Paul

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


Re: [R] sapply help

2012-02-04 Thread Milan Bouchet-Valat
Le vendredi 03 février 2012 à 18:51 +, William Dunlap a écrit :
> Instead of colSums(t(aMatrix)), why not the more
> direct rowSums(aMatrix)?
Because I felt it was more didactic. The question was about counting
occurrences per column, so using rowSums() could be a little confusing
without an explanation.

Of course, your solution is faster and cleaner.

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

2012-02-04 Thread Grace Kambey
Hi,
i have used the code below to come out with censored data with real values
but if i want to generate data from
q<-rweibull(25,2,4) that involves percent eg 5% or 10% censored i do not
know how to do it.
Can somebody show me how to do it.
Thank you in advance


 d <- Surv(time=c(27,100,100,53,78),event=c(1,0,0,1,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.


[R] 'deparse(substitute'))' then 'assign' in a S4 methods

2012-02-04 Thread cgenolin
Hi the list,

I am writing a function in which I need to affect a variable on a higher
level. My fnction could be:

++
fooBis <- function(x){
  nameObject <- deparse(substitute(x))
  print(nameObject)
  assign(nameObject,4,envir=parent.frame())
}
> fooBis(e)
[1] "e"
> e
[1] 4
-

(to simplify, this fnction can affect only the number 4. But it does it in
the parent frame).

My problem is that I use S4 programming. So the code becomes:

+
setGeneric("foo",function(x){standardGeneric("foo")})
setMethod("foo","ANY",
function(x){
  nameObject <- deparse(substitute(x))
  print(nameObject)
  assign(nameObject,4,envir=parent.frame())
   }
)
---
But it does not work since the definition of foo is now:

+
> foo
nonstandardGenericFunction for "foo" defined from package ".GlobalEnv"
function (x) 
{
standardGeneric("foo")
}

-
So how can I solve this problem? Is it possible to assign a value to a
variable on the upper level using S4?

Sincerely
Christophe


--
View this message in context: 
http://r.789695.n4.nabble.com/deparse-substitute-then-assign-in-a-S4-methods-tp4356748p4356748.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] Indistinguishable balls into distinguishable boxes

2012-02-04 Thread Petr Savicky
On Sat, Feb 04, 2012 at 08:45:20AM +0100, Marc Girondot wrote:
> Hi "the list" !
> 
> I would like to create a dataframe that answer to : "all the 
> combinations of the different way to distribute n indistinguishable 
> balls into k distinguishable boxes". Let take an example: 2 balls in 3 
> boxes:
> Box1 Box2 Box3
> 2   0   0
> 1   1   0
> 1   0   1
> 0   2   0
> 0   1   1
> 0   0   2

Hi.

The number of these placements is choose(n+k-1, k-1), which follows
from the representation of each placement by a sequence of balls and
boundaries between boxes, where "o" is a ball and "|" is a boundary.
For example (2, 0, 0) corresponds to "oo||" and
(1, 0, 1) is "o||o". Since this is a bijection, we can use it
for counting and also for generation.

  n <- 2
  k <- 3
  # generate all possible positions of the boundaries
  x <- combn(n+k-1, k-1)
  # compute the number of balls in each box
  a <- cbind(0, diag(k)) - cbind(diag(k), 0)
  t(a %*% rbind(0, x, n+k) - 1)

 [,1] [,2] [,3]
[1,]002
[2,]011
[3,]020
[4,]101
[5,]110
[6,]200

Hope this helps.

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.