Re: [R] beta regressions in R
see the package "betareg" in CRAN. 2007/7/29, Walter R. Paczkowski <[EMAIL PROTECTED]>: > >Good morning, >Does anyone know of a package or function to do a beta regression? >Thanks, >Walt Paczkowski > >_ >Walter R. Paczkowski, Ph.D. >Data Analytics Corp. >44 Hamilton Lane >Plainsboro, NJ 08536 >(V) 609-936-8999 >(F) 609-936-3733 > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 save results from chisq.test or mantelhaen.test to file
Maybe _dput_ is another way, and you can use _dget _ to get it back. 2007/7/1, Chuck Cleland <[EMAIL PROTECTED]>: > [EMAIL PROTECTED] wrote: > > Hi, > > > > I am new to these functions. I'm wondering if there is anyway to save the > > entire results (all attributes of the result object) from the chisq.test or > > mantelhaen.test functions? For example, from chisq.test function, you will > > have statistic, parameter, p.value, expected, etc. in the result list. How > > can I save all of them in one shot to, says, a text file or csv file? Thank > > you. > > > > - adschai > > You could unlist() the result, coerce it to a data frame, then use > write.table(). For example, something like this: > > write.table(as.data.frame(t(unlist(chisq.test(InsectSprays$count > 7, > InsectSprays$spray, quote=FALSE) > > or > > write.table(as.data.frame(unlist(chisq.test(InsectSprays$count > 7, > InsectSprays$spray))), quote=FALSE) > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > -- > Chuck Cleland, Ph.D. > NDRI, Inc. > 71 West 23rd Street, 8th floor > New York, NY 10010 > tel: (212) 845-4495 (Tu, Th) > tel: (732) 512-0171 (M, W, F) > fax: (917) 438-0894 > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] method of rpart when response variable is binary?
Dear all, I would like to model the relationship between y and x. y is binary variable, and x is a count variable which may be possion-distribution. I think it is better to divide x into intervals and change it to a factor before calling glm(y~x,data=dat,family=binomail). I try to use rpart. As y is binary, I use "class" method and get the following result. > rpart(y~x,data=dat,method="class") n=778 (22 observations deleted due to missingness) node), split, n, loss, yval, (yprob) * denotes terminal node 1) root 778 67 0 (0.91388175 0.08611825) * If with the default method, I get such a result. > rpart(y~x,data=dat) n=778 (22 observations deleted due to missingness) node), split, n, deviance, yval * denotes terminal node 1) root 778 61.230080 0.08611825 2) x< 19.5 750 53.514670 0.0773 4) x< 1.25 390 17.169230 0.04615385 * 5) x>=1.25 360 35.60 0.1110 * 3) x>=19.5 28 6.107143 0.32142860 * If I use 1.25 and 19.5 as the cutting points, change x into factor by >x2 <- cut(q34b,breaks=c(0,1.25,19.5,200),right=F) The coef in y~x2 is significant and makes sense. My problem is: is it OK use the default method in rpart when response varibale is binary one? Thanks. -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Factor analysis
I wrote some rough functions for principal factor, principal-components factor, and iterated principal factor analysis. I think they are workable, the same results as stata can be retained. In addition, functions for gls and uls factor analysis is in progress, which is based on the algorithms of SPSS. I get the same results by the gls factor analysis, and quite similiar result by the uls factor analysis. 2007/6/1, Sigbert Klinke <[EMAIL PROTECTED]>: > Hi, > > is there any other routine for factor analysis in R then factanal? > Basically I'am interested in another extraction method then the maximum > likelihood method and looking for unweighted least squares. > > Thanks in advance > > Sigbert Klinke > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Question about "evalq"
Got it. Thanks very much. On 5/28/07, Prof Brian Ripley <[EMAIL PROTECTED]> wrote: > How about 'traceback'? (It does not necesssarily show all the frames, but > it does help and the exceptions are fairly esoteric.) > > On Mon, 28 May 2007, ronggui wrote: > > > In that "the meaning of parent.frame depends on where it is > > evaluated", is there a nice way to figure out which frame an express > > is evaluated? for example, I would like to konw what does > > parent.frame(2) refer to. > > > >> f1 <- function(x,digits=5) lapply(x, f2) > >> f2 <- function(x) evalq(print(x+1,digits=digits),list(x=x),parent.frame(2)) > >> f1(list(x1=1)) > > Error in print.default(x + 1, digits = digits) : > > object "digits" not found > > > > > > On 5/27/07, Prof Brian Ripley <[EMAIL PROTECTED]> wrote: > >> The meaning of parent.frame depends on where it is evaluated. So one > >> should not expect it to do the same thing in two equivalent expressions > >> (and nor should one expect deparse to do so, for example). > >> > >> A pretty close analogy is that using a symbolic link in a file system is > >> equivalent to using the original file path, at least until you try '..' or > >> 'pwd' on the path. (In the case of 'pwd' it depends on the OS: POSIX > >> only requires '_an_ absolute pathname'.) > >> > >> On Sun, 27 May 2007, ronggui wrote: > >> > >> > The help page of eval says: The 'evalq' form is equivalent to > >> > 'eval(quote(expr), ...)'. But the following is not equivalent. Can > >> > anyone give me some explaination? Thanks very much. > >> > > >> >> f1 <- function(x,digits=5) lapply(x, f2) > >> >> f2 <- function(x) > >> eval(quote(print(x+1,digits=digits)),list(x=x),parent.frame(2)) > >> >> f1(list(x1=1)) > >> > [1] 2 > >> > $x1 > >> > [1] 2 > >> > > >> >> > >> >> f1 <- function(x,digits=5) lapply(x, f2) > >> >> f2 <- function(x) > >> evalq(print(x+1,digits=digits),list(x=x),parent.frame(2)) > >> >> f1(list(x1=1)) > >> > Error in print.default(x + 1, digits = digits) : > >> > object "digits" not found > >> > >> -- > >> Brian D. Ripley, [EMAIL PROTECTED] > >> 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 > >> > > > > > > > > -- > Brian D. Ripley, [EMAIL PROTECTED] > 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 > -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Question about "evalq"
That's great. I got it. Million thanks. On 5/28/07, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > On 5/27/07, ronggui <[EMAIL PROTECTED]> wrote: > > Hi,Gabor Grothendieck, Thanks very much. > > > > On 5/27/07, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > > > evalq looks like this: > > > > > >> evalq > > >function (expr, envir, enclos) > > >eval.parent(substitute(eval(quote(expr), envir, enclos))) > > > > > > > > > so it seems the difference is that > > > > > > - eval(quote(), envir, enclos) evaluates envir and enclos > > > in the current frame but > > > - evalq evaluates them in the parent.frame. > > > > > > This may be easier to see in the following example: > > > > Yeah, This example make the question easier to understand. > > > > >x <- "G" > > >f1 <- function() eval(quote(x), parent.frame()) > > >f2 <- function() evalq(x, parent.frame()) > > >f11 <- function() { > > > x <- "a" > > > f1() > > >} > > >f22 <- function() { > > > x <- "b" > > > f2() > > >} > > >f11() # a > > >f22() # G > > > > > > To avoid this problem pass a variable whose value is > > > to be enclos= rather than an expression to compute it: > > > > --This is a good idea. > > --If "evalq evaluates them in the parent.frame", I expected that if I > > change parent.frame(2) to parent.frame(1), I will get the answer.But I > > can not actually. So what's wrong with my understanding? > > > >f1 <- function(x,digits=5) lapply(x, f2) > >f2 <- function(x) { > > evalq(print(digits), list(x=x), parent.frame(1)) > >} > >f1(list(x1=1)) ##Error in print(digits) : object "digits" not found > > > Good point. Insert a browser statement where the parent.frame > call was and when it stops do a traceback. That will show you > what the call stack looks like at that point in time. > > > > f1 <- function(x,digits=5) lapply(x, f2) > > f2 <- function(x) evalq(print(digits), list(x=x), { browser() } ) > > f1(list(x1=1)) ##Error in print(digits) : object "digits" not found > Called from: eval(quote(print(digits)), list(x = x), { > browser() > }) > Browse[1]> traceback() > 10: print(digits) > 9: eval(expr, envir, enclos) > 8: eval(quote(print(digits)), list(x = x), browser()) > 7: eval(expr, envir, enclos) > 6: eval(expr, p) > 5: eval.parent(substitute(eval(quote(expr), envir, enclos))) > 4: evalq(print(digits), list(x = x), browser()) > 3: FUN(X[[1L]], ...) > 2: lapply(x, f2) > 1: f1(list(x1 = 1)) > Browse[1]> > -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Question about "evalq"
Hi,Gabor Grothendieck, Thanks very much. On 5/27/07, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > evalq looks like this: > >> evalq >function (expr, envir, enclos) >eval.parent(substitute(eval(quote(expr), envir, enclos))) > > > so it seems the difference is that > > - eval(quote(), envir, enclos) evaluates envir and enclos > in the current frame but > - evalq evaluates them in the parent.frame. > > This may be easier to see in the following example: Yeah, This example make the question easier to understand. >x <- "G" >f1 <- function() eval(quote(x), parent.frame()) >f2 <- function() evalq(x, parent.frame()) >f11 <- function() { > x <- "a" > f1() >} >f22 <- function() { > x <- "b" > f2() >} >f11() # a >f22() # G > > To avoid this problem pass a variable whose value is > to be enclos= rather than an expression to compute it: --This is a good idea. --If "evalq evaluates them in the parent.frame", I expected that if I change parent.frame(2) to parent.frame(1), I will get the answer.But I can not actually. So what's wrong with my understanding? f1 <- function(x,digits=5) lapply(x, f2) f2 <- function(x) { evalq(print(digits), list(x=x), parent.frame(1)) } f1(list(x1=1)) ##Error in print(digits) : object "digits" not found >f1 <- function(x,digits=5) lapply(x, f2) >f2 <- function(x) { > pf2 <- parent.frame(2) > evalq(print(digits), list(x=x), pf2) >} >f1(list(x1=1)) # 5 > > > > On 5/26/07, ronggui <[EMAIL PROTECTED]> wrote: > > The help page of eval says: The 'evalq' form is equivalent to > > 'eval(quote(expr), ...)'. But the following is not equivalent. Can > > anyone give me some explaination? Thanks very much. > > > > > f1 <- function(x,digits=5) lapply(x, f2) > > > f2 <- function(x) > > > eval(quote(print(x+1,digits=digits)),list(x=x),parent.frame(2)) > > > f1(list(x1=1)) > > [1] 2 > > $x1 > > [1] 2 > > > > > > > > f1 <- function(x,digits=5) lapply(x, f2) > > > f2 <- function(x) > > > evalq(print(x+1,digits=digits),list(x=x),parent.frame(2)) > > > f1(list(x1=1)) > > Error in print.default(x + 1, digits = digits) : > > object "digits" not found > > > > > > > > -- > > Ronggui Huang > > Department of Sociology > > Fudan University, Shanghai, China > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Question about "evalq"
In that "the meaning of parent.frame depends on where it is evaluated", is there a nice way to figure out which frame an express is evaluated? for example, I would like to konw what does parent.frame(2) refer to. > f1 <- function(x,digits=5) lapply(x, f2) > f2 <- function(x) evalq(print(x+1,digits=digits),list(x=x),parent.frame(2)) > f1(list(x1=1)) Error in print.default(x + 1, digits = digits) : object "digits" not found On 5/27/07, Prof Brian Ripley <[EMAIL PROTECTED]> wrote: > The meaning of parent.frame depends on where it is evaluated. So one > should not expect it to do the same thing in two equivalent expressions > (and nor should one expect deparse to do so, for example). > > A pretty close analogy is that using a symbolic link in a file system is > equivalent to using the original file path, at least until you try '..' or > 'pwd' on the path. (In the case of 'pwd' it depends on the OS: POSIX > only requires '_an_ absolute pathname'.) > > On Sun, 27 May 2007, ronggui wrote: > > > The help page of eval says: The 'evalq' form is equivalent to > > 'eval(quote(expr), ...)'. But the following is not equivalent. Can > > anyone give me some explaination? Thanks very much. > > > >> f1 <- function(x,digits=5) lapply(x, f2) > >> f2 <- function(x) > >> eval(quote(print(x+1,digits=digits)),list(x=x),parent.frame(2)) > >> f1(list(x1=1)) > > [1] 2 > > $x1 > > [1] 2 > > > >> > >> f1 <- function(x,digits=5) lapply(x, f2) > >> f2 <- function(x) evalq(print(x+1,digits=digits),list(x=x),parent.frame(2)) > >> f1(list(x1=1)) > > Error in print.default(x + 1, digits = digits) : > > object "digits" not found > > -- > Brian D. Ripley, [EMAIL PROTECTED] > 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 > -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Question about "evalq"
The help page of eval says: The 'evalq' form is equivalent to 'eval(quote(expr), ...)'. But the following is not equivalent. Can anyone give me some explaination? Thanks very much. > f1 <- function(x,digits=5) lapply(x, f2) > f2 <- function(x) > eval(quote(print(x+1,digits=digits)),list(x=x),parent.frame(2)) > f1(list(x1=1)) [1] 2 $x1 [1] 2 > > f1 <- function(x,digits=5) lapply(x, f2) > f2 <- function(x) evalq(print(x+1,digits=digits),list(x=x),parent.frame(2)) > f1(list(x1=1)) Error in print.default(x + 1, digits = digits) : object "digits" not found -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] What's wrong with my code ?
On 5/19/07, ronggui <[EMAIL PROTECTED]> wrote: > I try to code the ULS factor analysis descrbied in > ftp://ftp.spss.com/pub/spss/statistics/spss/algorithms/ factor.pdf > # see PP5-6 > > factanal.fit.uls <- function(cmat, factors, start=NULL, lower = 0.005, > control = NULL, ...) > { > FAfn <- function(Psi, S, q) > { > Sstar <- S - diag(Psi) > E <- eigen(Sstar, symmetric = TRUE, only.values = TRUE) > e <- E$values[-(1:q)] > e <- sum(e^2/2) > e > } > > FAgr <- function(Psi, S, q) > { > Sstar <- S - diag(Psi) > E <- eigen(Sstar, symmetric = TRUE) > L <- E$vectors[, -(1:q), drop = FALSE] > e <- E$values[-(1:q)] > gr <- 2*Psi*((L^2)%*%e) > gr > } > > p <- ncol(cmat) > if(is.null(start)) > start <- (1 - 0.5*factors/p)/diag(solve(cmat)) > res <- optim(start, FAfn, > FAgr, > method="L-BFGS-B", > lower = lower, upper = 1, > control = c(list(fnscale=1, > parscale = rep(0.01, length(start))), control), > q = factors, S = cmat) I forgot to tell that the code to get "start" and " res <- optim() " if from stats:::factanal.fit.mle. > res > } > > covmat <- > structure(c(1, 0.0920030858518061, 0.053952442382614, -0.0380048634941013, > 0.237986469993129, 0.243144461077282, 0.0920030858518061, 1, > 0.328163804480881, 0.142002180914605, -0.139369611642031, -0.0670944471678571, > 0.053952442382614, 0.328163804480881, 1, 0.267648727315665, > -0.0549987508157441, > -0.107488501744669, -0.0380048634941013, 0.142002180914605, 0.267648727315665, > 1, -0.0566976575082817, -0.132943658387513, 0.237986469993129, > -0.139369611642031, -0.0549987508157441, -0.0566976575082817, > 1, 0.352367996102745, 0.243144461077282, -0.0670944471678571, > -0.107488501744669, -0.132943658387513, 0.352367996102745, 1), .Dim = c(6L, > 6L), .Dimnames = list(c("bg2cost1", "bg2cost2", "bg2cost3", "bg2cost4", > "bg2cost5", "bg2cost6"), c("bg2cost1", "bg2cost2", "bg2cost3", > "bg2cost4", "bg2cost5", "bg2cost6"))) > > > > factanal.fit.uls(covmat,2) > $par > bg2cost1 bg2cost2 bg2cost3 bg2cost4 bg2cost5 bg2cost6 > 0.7454829 0.7191459 0.6969019 0.7611750 0.6940870 0.6930580 > > $value > [1] 0.02167674 > > $counts > function gradient > 21 21 > > $convergence > [1] 52 > > $message > [1] "ERROR: ABNORMAL_TERMINATION_IN_LNSRCH" > > -- > Ronggui Huang > Department of Sociology > Fudan University, Shanghai, China > -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] What's wrong with my code ?
I try to code the ULS factor analysis descrbied in ftp://ftp.spss.com/pub/spss/statistics/spss/algorithms/ factor.pdf # see PP5-6 factanal.fit.uls <- function(cmat, factors, start=NULL, lower = 0.005, control = NULL, ...) { FAfn <- function(Psi, S, q) { Sstar <- S - diag(Psi) E <- eigen(Sstar, symmetric = TRUE, only.values = TRUE) e <- E$values[-(1:q)] e <- sum(e^2/2) e } FAgr <- function(Psi, S, q) { Sstar <- S - diag(Psi) E <- eigen(Sstar, symmetric = TRUE) L <- E$vectors[, -(1:q), drop = FALSE] e <- E$values[-(1:q)] gr <- 2*Psi*((L^2)%*%e) gr } p <- ncol(cmat) if(is.null(start)) start <- (1 - 0.5*factors/p)/diag(solve(cmat)) res <- optim(start, FAfn, FAgr, method="L-BFGS-B", lower = lower, upper = 1, control = c(list(fnscale=1, parscale = rep(0.01, length(start))), control), q = factors, S = cmat) res } covmat <- structure(c(1, 0.0920030858518061, 0.053952442382614, -0.0380048634941013, 0.237986469993129, 0.243144461077282, 0.0920030858518061, 1, 0.328163804480881, 0.142002180914605, -0.139369611642031, -0.0670944471678571, 0.053952442382614, 0.328163804480881, 1, 0.267648727315665, -0.0549987508157441, -0.107488501744669, -0.0380048634941013, 0.142002180914605, 0.267648727315665, 1, -0.0566976575082817, -0.132943658387513, 0.237986469993129, -0.139369611642031, -0.0549987508157441, -0.0566976575082817, 1, 0.352367996102745, 0.243144461077282, -0.0670944471678571, -0.107488501744669, -0.132943658387513, 0.352367996102745, 1), .Dim = c(6L, 6L), .Dimnames = list(c("bg2cost1", "bg2cost2", "bg2cost3", "bg2cost4", "bg2cost5", "bg2cost6"), c("bg2cost1", "bg2cost2", "bg2cost3", "bg2cost4", "bg2cost5", "bg2cost6"))) > factanal.fit.uls(covmat,2) $par bg2cost1 bg2cost2 bg2cost3 bg2cost4 bg2cost5 bg2cost6 0.7454829 0.7191459 0.6969019 0.7611750 0.6940870 0.6930580 $value [1] 0.02167674 $counts function gradient 21 21 $convergence [1] 52 $message [1] "ERROR: ABNORMAL_TERMINATION_IN_LNSRCH" -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] from R to html
Try the package "R2HTML". On 4/26/07, elyakhlifi mustapha <[EMAIL PROTECTED]> wrote: > hello, > here's a data frame > > > A2 >Gr_C Id_Cara Libc_C Unit_C > 1 30770 743 SCLERO CAP% % > 2 30770 627 RDT GR PR & SEC q/ha > 3 30770 638PEUPL M2 nb/m2 > 4 30770 740 SCLEROTI % COLL % > 5 30770 739 VERSE RECOLT%NB % > > and I 'd like to export it to html > to do this I thougth that the script below it was good > > > write.table(A, "C:/Documents and Settings/melyakhlifi/Bureau/sortie.html", > > col.names = TRUE) > > but the results doesn't satisfy me it seems like below > > "Gr_C" "Id_Cara" "Libc_C" "Unit_C" "1" 30770 743 "SCLERO CAP%" "%" "2" 30770 > 627 "RDT GR PR & SEC" "q/ha" "3" 30770 638 "PEUPL M2" "nb/m2" "4" 30770 740 > "SCLEROTI % COLL" "%" "5" 30770 739 "VERSE RECOLT%NB" "%" > > In fact I'd like keep the same format with columns and rows I knew now that > the command I used it's insufficient and I wish to know how I could to export > ma data frame to html using html langage (with marks out like > .). > thanks. > > > > ___ > > > > > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] When to use quasipoisson instead of poisson family
On 4/10/07, Prof Brian Ripley <[EMAIL PROTECTED]> wrote: > On Tue, 10 Apr 2007, Achim Zeileis wrote: > > > On Tue, 10 Apr 2007, ronggui wrote: > > > >> It seems that MASS suggest to judge on the basis of > >> sum(residuals(mode,type="pearson"))/df.residual(mode). > > Not really; that is the conventional moment estimator of overdispersion > and it does not suffer from the severe biases the unreferenced estimate > below has (and are illustrated in MASS). > > >> My question: Is > >> there any rule of thumb of the cutpoiont value? > >> > >> The paper "On the Use of Corrections for Overdispersion" > > Whose paper? It is churlish not to give credit, and unhelpful to your > readers not to give a proper citation. Thanks for pointing this out. There is the citation: @article{lindsey1999, title={On the use of corrections for overdispersion}, author={Lindsey, JK}, journal={Applied Statistics}, volume={48}, number={4}, pages={553--561}, year={1999}, } > >> suggests overdispersion exists if the deviance is at least twice the > >> number of degrees of freedom. > > Overdispersion _exists_: 'all models are wrong but some are useful' > (G.E.P. Box). The question is if it is important in your problem, not it > if is detectable. > > There are also formal tests for over-dispersion. I've implemented one for > > a package which is not yet on CRAN (code/docs attached), another one is > > implemented in odTest() in package "pscl". The latter also contains > > further count data regression models which can deal with both > > over-dispersion and excess zeros in count data. A vignette explaining the > > tools is about to be released. > > There are, but like formal tests for outliers I would not advise using > them, as you may get misleading inferences before they are significant, > and they can reject when the inferences from the small model are perfectly > adequate. > > In general, it is a much better idea to expand your models to take account > of the sorts of departures your anticipate rather than post-hoc test for > those departures and then if those tests do not fail hope that there is > little effect on your inferences. Which is the better (or ) best way to expand the existing model? by adding some other relevant independent variables or by using other more suitable model like "Negative Binomial Generalized Linear Model"? Thanks! > The moment estimator \phi of over-dispersion gives you an indication of > the likely effects on your inferences: e.g. estimated standard errors are > proportional to \sqrt(\phi). Having standard errors which need inflating > by 40% seems to indicate that the rule you quote is too optimistic (even > when its estimator is reliable). > > -- > Brian D. Ripley, [EMAIL PROTECTED] > 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 > -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] When to use quasipoisson instead of poisson family
It seems that MASS suggest to judge on the basis of sum(residuals(mode,type="pearson"))/df.residual(mode). My question: Is there any rule of thumb of the cutpoiont value? The paper "On the Use of Corrections for Overdispersion" suggests overdispersion exists if the deviance is at least twice the number of degrees of freedom. Are there any further hints? Thanks. -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Reading a csv file row by row
And _file()_ is helpful in such situation. R/S-PLUS Fundamentals and Programming Techniques by Thomas Lumley has something relavant in page 185 (total page is 208). I believe you can find it by googling. On 4/6/07, Martin Becker <[EMAIL PROTECTED]> wrote: > readLines (which is mentioned in the "See also" section of ?scan with > the hint "to read a file a line at a time") should work. > > Regards, > Martin > > Yuchen Luo schrieb: > > Hi, my friends. > > When a data file is large, loading the whole file into the memory all > > together is not feasible. A feasible way is to read one row, process it, > > store the result, and read the next row. > > > > > > In Fortran, by default, the 'read' command reads one line of a file, which > > is convenient, and when the same 'read' command is executed the next time, > > the next row of the same file will be read. > > > > I tried to replicate such row-by-row reading in R.I use scan( ) to do so > > with the "skip= xxx " option. It takes only seconds when the number of the > > rows is within 1000. However, it takes hours to read 1 rows. I think it > > is because every time R reads, it needs to start from the first row of the > > file and count xxx rows to find the row it needs to read. Therefore, it > > takes more time for R to locate the row it needs to read. > > > > Is there a solution to this problem? > > > > Your help will be highly appreciated! > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] C interface
On 3/29/07, Prof Brian Ripley <[EMAIL PROTECTED]> wrote: > We don't know what document that is, and you haven't given us a useful > pointer, have you? And the authors (presumably Roger Peng and Jan de > Leeuw) deserve credit. It is a great point. I have googled and confirm that the authors are Roger Peng and Jan de Leeuw. Here is the link http://www.biostat.jhsph.edu/~rpeng/docs/interface.pdf > The definitive documentation is the 'Writing R Extensions' manual which > ships with R. There is also a lot in 'S Programming' (see the books in > the FAQ), and many examples in the R sources and contributed packages. > > On Thu, 29 Mar 2007, [EMAIL PROTECTED] wrote: > > > > > Hi All > > I have read this document - An Introduction to the .C Interface to R, > > which primarily tells how to interface C language with R. > > Is there and more elaborative and online documentation regarding this > > interface. > > > > Any pointers appreciated > > -thanks > > -gaurav > > > > > > DISCLAIMER AND CONFIDENTIALITY CAUTION:\ \ This message and ...{{dropped}} > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/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, [EMAIL PROTECTED] > 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@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] question on suppressing error messages with Rmath library
op <- options(warn=-1) [main codes here] options(op) On 3/21/07, Ranjan Maitra <[EMAIL PROTECTED]> wrote: > Dear list, > > I have been using the Rmath library for quite a while: in the current > instance, I am calling dnt (non-central t density function) repeatedly for > several million. When the argument is small, I get the warning message: > > full precision was not achieved in 'pnt' > > which is nothing unexpected. (The density calls pnt, if you look at the > function dnt.) However, to have this happen a huge number of times, when the > optimizer is churning through the dataset is bothersome, but more > importantly, a bottleneck in terms of speed. Is it possible to switch this > off? Is there an setting somewhere that I am missing? > > Many thanks and best wishes, > Ranjan > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] question about Style in odfWeave
I would like to drow the topBorder and the buttomBorder, which value should be set. I try set them to "auto", but it does not make any differences. Thanks. > getStyleDefs()$noBorder $type [1] "Table Cell" $backgroundColor [1] "transparent" $padding [1] "0.0382in" $verticalAlign [1] "auto" $padding [1] "0.0382in" $leftBorder [1] "none" $rightBorder [1] "none" $topBorder [1] "none" $bottomBorder [1] "none" -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Error with get_all_vars()
> get_all_vars(dist ~ speed, data = cars) Error in `row.names<-.data.frame`(`*tmp*`, value = c(NA, -50L)) : invalid 'row.names' length > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status Under development (unstable) major 2 minor 5.0 year 2007 month 03 day13 svn rev40832 language R version.string R version 2.5.0 Under development (unstable) (2007-03-13 r40832) -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 installation of littler-0.0.10. under Free BSD 6.2
MyBSD% make -v make: no target to make. MyBSD% gmake -v GNU Make 3.81 Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This program built for i386-portbld-freebsd6.2 MyBSD% cd software/littler-0.0.10 MyBSD% make R_HOME= /usr/local/bin/R --silent --vanilla --slave < > autoloads.h Syntax error: redirection unexpected *** Error code 2 Stop in /home/ronggui/software/littler-0.0.10. MyBSD% export MAKE=gmake MyBSD% make R_HOME= /usr/local/bin/R --silent --vanilla --slave < > autoloads.h Syntax error: redirection unexpected *** Error code 2 Stop in /home/ronggui/software/littler-0.0.10. MyBSD% %From pkg_info -x make I find automake-1.4.6_2 and gnu-automake-1.9.6 is installed in the BSD box. On 3/13/07, Jeffrey Horner <[EMAIL PROTECTED]> wrote: Hello, Dirk Eddelbuettel wrote: > On 12 March 2007 at 13:38, ronggui wrote: [...] > | MyBSD% make > | R_HOME= /usr/local/bin/R --silent --vanilla --slave < > autoloads.h > | Syntax error: redirection unexpected > | *** Error code 2 > | > | Stop in /home/ronggui/software/littler-0.0.10. > | > | Anyone knows why and any hints to the solution? Thanks in advance. This is a problem with your make command not expanding '$<' . CCan you ruun make -v to tell us what version it is? Thanks, jeff > > Jeff and I know that the world was created inside a bash shell. And indeed it was! ;) > > Seriously, can you try running configure inside a shell with working redirects? > If you can't then you may need to simulate by hand what this would do, > outside of configure, and then run make. > > Let us know. > > Dirk > > | -- > | Ronggui Huang > | Department of Sociology > | Fudan University, Shanghai, China > | 黄荣贵 > | 复旦大学社会学系 -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China 黄荣贵 复旦大学社会学系 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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 installation of littler-0.0.10. under Free BSD 6.2
MyBSD% ./configure checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for gawk... no checking for mawk... no checking for nawk... nawk checking whether make sets $(MAKE)... yes checking build system type... i386-unknown-freebsd6.2 checking host system type... i386-unknown-freebsd6.2 checking for a BSD-compatible install... /usr/bin/install -c checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking for style of include used by make... GNU checking dependency style of gcc... gcc3 checking how to run the C preprocessor... gcc -E checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking stdio.h usability... yes checking stdio.h presence... yes checking for stdio.h... yes checking for string.h... (cached) yes checking errno.h usability... yes checking errno.h presence... yes checking for errno.h... yes checking for stdlib.h... (cached) yes checking for sys/types.h... (cached) yes checking for sys/stat.h... (cached) yes checking for unistd.h... (cached) yes checking getopt.h usability... yes checking getopt.h presence... yes checking for getopt.h... yes checking whether sys/types.h defines makedev... yes checking for setenv... yes checking for gettimeofday... yes checking for time... yes checking for R... /usr/local/bin/R checking if R was built as a shared library... yes checking for install_name_tool... no configure: creating ./config.status config.status: creating Makefile config.status: creating config.h config.status: config.h is unchanged config.status: executing depfiles commands MyBSD% make R_HOME= /usr/local/bin/R --silent --vanilla --slave < > autoloads.h Syntax error: redirection unexpected *** Error code 2 Stop in /home/ronggui/software/littler-0.0.10. Anyone knows why and any hints to the solution? Thanks in advance. -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China 黄荣贵 复旦大学社会学系 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Where can I get the latex format manual?
In www.r-project.org I can find html and pdf format, and the R-x.x-x/doc/manual has texinfo format only. I can not find latex format manual. Am I miss something? Thanks for your hints. -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China 黄荣贵 复旦大学社会学系 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] SQLite: When reading a table, a "\r" is padded onto the last column. Why?
On 1/4/07, Seth Falcon <[EMAIL PROTECTED]> wrote: Prof Brian Ripley <[EMAIL PROTECTED]> writes: > [I am not sure who is actually maintaining RSQLite, so am Cc: both the > stated maintainer and the person who prepared the package for > distribution. The posting guide asked you to contact the maintainer: > what response did _you_ get?] For the record, I will be (have been) taking on the maintainer role for RSQLite. The Maintainer field will be updated in the next version. As to the '\r' problem, a release candidate RSQLite 0.4-17 is available here: http://bioconductor.org/packages/misc/ This version uses prepared queries to implement dbWriteTable. This should resolve the '\r' issue on Windows and should also be considerably more efficient. Soren, can you give this one a try and let me know if it works for you? When write a data frame to db table, the problem of "\r" is fixed. But for importing data frome file, the problem is still there. When if the final line lacks the eol sign "\n", "\001x\001(" comes up. dbWriteTable(con,"test","c:/test.txt",sep="\t",head=T,over=T,eol="\n") [1] TRUE Warning message: incomplete final line found by readTableHeader on 'c://test.txt' dbReadTable(con,"test") a b 1 1 2\r 2 3 \r 3 1 3\r 4 0 5\001x\001( dbWriteTable(con,"test","c:/test.txt",sep="\t",head=T,over=T,eol="\n") [1] TRUE dbReadTable(con,"test") a b 1 1 2\r 2 3 \r 3 1 3\r 4 0 5\r data(USArrests) dbWriteTable(con, "USArrests", USArrests, overwrite = T) [1] TRUE dbReadTable(con, "USArrests") Murder Assault UrbanPop Rape Alabama 13.2 236 58 21.2 Alaska 10.0 263 48 44.5 Arizona 8.1 294 80 31.0 Arkansas 8.8 190 50 19.5 California9.0 276 91 40.6 Colorado 7.9 204 78 38.7 sessionInfo() R version 2.4.0 Patched (2006-11-21 r39949) i386-pc-mingw32 locale: LC_COLLATE=Chinese_People's Republic of China.936;LC_CTYPE=Chinese_People's Republic of China.936;LC_MONETARY=Chinese_People's Republic of China.936;LC_NUMERIC=C;LC_TIME=Chinese_People's Republic of China.936 attached base packages: [1] "stats" "graphics" "grDevices" "utils" "datasets" "methods" [7] "base" other attached packages: RSQLite DBI "0.4-17" "0.1-11" Recent work on RSQLite has focused on integrating SQLite3's type system into the interface. We now rely on the column type in the DB when retrieving results. Previously, type.convert was used. I'm fairly certain these changes will result in changes in behavior -- in most cases, I think the changes are for the better. + seth __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China 黄荣贵 复旦大学社会学系 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] SQLite: When reading a table, a "\r" is padded onto the last column. Why?
RSQLite can import data from a large file directly (via "dbWriteTable"). This future is quite appealing. On 1/3/07, Prof Brian Ripley <[EMAIL PROTECTED]> wrote: > I guess you are using package RSQLite without telling us (or telling us > the version), and that your example is incomplete? > > Using RSiteSearch("RSQLite Windows") quickly shows that this is a > previously reported problem with the package, e.g.: > > http://finzi.psych.upenn.edu/R/Rhelp02a/archive/72515.html > > I believe the issue is that RSQLite actually writes out a CRLF-terminated > text file and imports that into SQLite. (I checked version 0.4-15.) It > seems function safe.write() needs to be modified to write to a binary-mode > connection since SQLite appears to require LF-terminated files. > > Using RODBC to work with SQLite databases works correctly even under > Windows (and is much more efficient at writing to the database). > > [I am not sure who is actually maintaining RSQLite, so am Cc: both the > stated maintainer and the person who prepared the package for > distribution. The posting guide asked you to contact the maintainer: what > response did _you_ get?] > > > On Wed, 3 Jan 2007, Søren Højsgaard wrote: > > > Hi, > > > > I put the iris data into a SQLite database with > > > > dbWriteTable(con, "iris", iris, row.names=F, overwrite = T) > > > > Then I retrieve data from the database with > > > > rs <- dbSendQuery(con, "select * from iris") > > d1 <- fetch(rs) > > dbClearResult(rs) > > > > Then I get > >> head(d1) > > Sepal_Length Sepal_Width Petal_Length Petal_Width Species > > 1 5.1 3.5 1.4 0.2 setosa\r > > 2 4.9 3.0 1.4 0.2 setosa\r > > 3 4.7 3.2 1.3 0.2 setosa\r > > 4 4.6 3.1 1.5 0.2 setosa\r > > 5 5.0 3.6 1.4 0.2 setosa\r > > 6 5.4 3.9 1.7 0.4 setosa\r > > > > Can anyone explain the extra "\r" at the end? I am on Windows XP using R > > 2.4.1 > > Thanks in advance > > Søren > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/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, [EMAIL PROTECTED] > 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@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > > -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China 黄荣贵 复旦大学社会学系 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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 load Rcmd without Commander() ?
I would like to use the reliability() function in Rcmdr package, but not the GUI, so I would to load Rcmd without Commander() running automatically. Is there any easy way to get it? Thanks. -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China 黄荣贵 复旦大学社会学系 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Extract some character from a character vector of length 1
the content of th character vector (of length 1) is as follows: a <- "something2 pat1 name1 pat2 something2pat1 name2 pat2pat1 name3 pat2 " I would like to extract the character bewteen pat1 and pat2. That's to say, I would like to get a vecter of c("name1", "name2","name3"). What I did is use strsplit() twise. But I wonder if there any function to this specific task? Thanks. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] writing character to a file in UTF-8
Dear lister, I would like to now if there a universal way to writing a character vector to a file in UTF-8 encoding? By " universal", I mean a way which works under Linux, Windows and Mac. Thanks in advance! -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Latent models
Is "ltm" what you want? packageDescription("ltm") Package: ltm Title: Latent Trait Models under IRT Version: 0.6-1 Date: 2006-10-02 Author: Dimitris Rizopoulos <[EMAIL PROTECTED]> Maintainer: Dimitris Rizopoulos <[EMAIL PROTECTED]> Description: Analysis of multivariate dichotomous and polytomous data using latent trait models under the Item Response Theory approach. It includes the Rasch, the Two-Parameter Logistic, the Birnbaum's Three-Parameter, and the Graded Response Models. Depends: R(>= 2.3.0), MASS, gtools, msm LazyLoad: yes LazyData: yes License: GPL version 2 or later URL: http://wiki.r-project.org/rwiki/doku.php?id=packages:cran:ltm Packaged: Tue Oct 3 09:07:38 2006; dimitris Built: R 2.4.0; ; 2006-10-03 17:16:04; windows If you are looking function for "Latent Class Analysis (LCA)", then "lca" in package e1071 is what you want. On 11/22/06, Bi-Info (http://members.home.nl/bi-info) <[EMAIL PROTECTED]> wrote: Hai, Can anyone help me with some literature (R related) about latent models? Thanx, Wilfred __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China 黄荣贵 复旦大学社会学系 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] read file problem
You should pay attention to the argument na.string. na.strings: a character vector of strings which are to be interpreted as 'NA' values. Blank fields are also considered to be missing values in logical, integer, numeric and complex fields. On 11/3/06, Luis Ridao Cruz <[EMAIL PROTECTED]> wrote: R-help, I have the following file I want to import to R (some lines removed) Calibrated CTD data for station:00280001 Calibrated:23/8 2001, Salinity Unsmoothed, Fluorescence Uncalibrated Maximum observed depth:36 m QUAL has one digit for each of pressure, temp., sal. and fluor. QUAL=1:Uncal., QUAL=2:OK, QUAL=6:Interp., QUAL=9:No data DEPTH CTDPRS CTDTMP CTDSAL RAWFLU NUMB. QUAL MDBAR IPTS-68 PSS-78 OBS. *** *** *** *** 1 1.0 2999 2 2.0 5.9793 35.1629.10717 2221 3 3.0 5.9797 35.1631.10117 2221 4 4.0 5.9809 35.1631.11812 2221 5 5.1 5.9811 35.1629.11542 2221 6 6.1 5.9810 35.1631.11618 2221 7 7.1 5.9797 35.1631.11615 2221 8 8.1 5.9798 35.1630.10213 2221 9 9.1 5.9792 35.1629.11311 2221 ... . If I use : read.table(file, skip = 10) it works fine but sometimes the missing data are not only in line number 1 ( 1 1.0 2999) but in lines 1,2,3,,, and therefore R fails to import the data file How can I fix it? I have tried with the arguments strip.white = TRUE , fill = TRUE , blank.lines.skip = TRUE but still not get what I want Thanks in advance > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 4.0 year 2006 month 10 day03 svn rev39566 language R version.string R version 2.4.0 (2006-10-03) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China 黄荣贵 复旦大学社会学系 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Is there any method to do spatial sampling?
I have a map of a district (which is JPG format), and I want to do a sptial sampling based on the map. So is there any function to do spatial sampling of this type? Thanks! -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China 黄荣贵 复旦大学社会学系 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Automatic File Reading [Broadcast]
2006/10/29, Wensui Liu <[EMAIL PROTECTED]>: Andy, First of all, thanks for your solution. When I test your code, it doesn't work. I am not sure if I miss something. Here is the code I tested: flist<-list.files(path = file.path(, "c:\\"),pattern="[.]csv$") First of all, I think the command should be as follows: flist<-list.files(path = file.path("c:\\"),pattern="[.]csv$") csvlist<-lapply(flist, read.csv, header = TRUE) Here is the error: Error in file(file, "r") : unable to open connection In addition: Warning message: cannot open file 'test1.csv', reason 'No such file or directory' Maybe your should reset working directory. the flist is the relative path so you should set the directory where the data files are (I guess is "c://" in your case) as working directory. setwd("c://") csvlist<-lapply(flist, read.csv, header = TRUE) Thank you so much! On 10/18/06, Liaw, Andy <[EMAIL PROTECTED]> wrote: > Works on all platforms: > > flist <- list.files(path=file.path("somedir", "somewhere"), > pattern="[.]csv$") > csvlist <- lapply(flist, read.csv, header=TRUE) > whateverList <- lapply(csvlist, whatever) > > Andy > > From: Richard M. Heiberger > > > > Wensui Lui asks: > > > is there a similar way to read all txt or csv files with same > > > structure from a folder? > > > > > > > > On Windows I use this construct to find all files with the > > specified wild card name. > > I used the "\\" in the file paths with the translate=FALSE, > > because the "/" in > > the DOS switches "/w/B" must not be translated. On Windows > > this picks up > > both lower and upper case filenames > > > > A similar construct can be written for Unix. > > > > tmp <- shell('dir c:\\HOME\\rmh\\tmp\\*.R /w/B', intern=TRUE, > > translate=FALSE) ##msdos > > for (i in tmp) source(paste("c:\\HOME\\rmh\\tmp\\", i, sep="")) > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > > > > > > > -- > Notice: This e-mail message, together with any attachment...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China 黄荣贵 复旦大学社会学系 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] cross tabs with percents?
Maybe _CrossTable_ in gmodels package is what you want. 2006/10/22, Larry White <[EMAIL PROTECTED]>: > > -- apologies if this is a dup - i got a bounce saying the message was > unprocessed. > > Is there a straightforward way to get a table with percents in the > cells rather than counts? I've looked at table, ftable, xtabs, and > ctab, which did the conversion but returned the results in a single > row without labels. > > any suggestions are appreciated. > thank you. > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- »ÆÈÙ¹ó Department of Sociology Fudan University [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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 replace the second "-"
I have a string vector like these: [1] "1-1-1" "1-1-2" "1-2-1" And I wanna replace the second "-" with "0", that is, I wanna get the result like: [1] "1-101" "1-102" "1-201". How should I write the Regular Expressions? Thanks! -- »ÆÈÙ¹ó Department of Sociology Fudan University [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Possible bug?
Yes, the installer missed some file(s) in RHOME/bin. When I choose "Message translations", the /bin directory contains the following files. R.dll R.exe RSetReg.exe Rblas.dll Rcmd.exe Rgui.exe Rlapack.dll Rproxy.dll Rterm.exe Stangle.sh Sweave.sh helpPRINT.bat md5check.exe When I install without choosing "Message translations", the /bin directory contains the following files. INSTALL R.dll R.exe REMOVE RSetReg.exe Rblas.dll Rcmd.exe Rd2dvi.sh Rd2txt Rdconv Rdiff.sh Rgui.exe Rlapack.dll Rprof Rproxy.dll Rterm.exe SHLIB Sd2Rd Stangle.sh Sweave.sh build check helpPRINT.bat massage-Examples md5check.exe On 10/4/06, Duncan Murdoch <[EMAIL PROTECTED]> wrote: > > On 10/4/2006 12:02 AM, Ray Brownrigg wrote: > > On Wednesday 04 October 2006 14:17, Duncan Murdoch wrote: > >> On 10/3/2006 9:00 PM, ronggui wrote: > >>> This morning I downloaded R-2.4.0 and install in under Windows. I > >>> customized the installation and choose "Message translations",but I > could > >>> not launch Rgui.exe successfully( Rterm.exe worked fine). If I did't > >>> choose "Message translations", Rgui.exe worked fine. > >>> > >>> "Message translations" is Simplified Chinese. > >> Did you test any of the betas or release candidates? I run an English > >> language version of Windows, and I don't even get offered the chance to > >> install in Simplified Chinese, so I certainly didn't test this. > >> > >> Duncan Murdoch > >> > > > >> 7*runif(1) > > [1] 2.897160 > > > > Well, I have a (self compiled) R-2.4.0 beta (2006-09-24 r39497) which > doesn't > > exhibit the behaviour in the same environment (Windows XP Professional > > English version but with Simplified Chinese set as the locale) that the > > released R-2.4.0-win32.exe does. [Perhaps my version didn't set up the > > equivalent of "Message translations" so this may be a red herring, but > it > > does output the startup message in Chinese, and error messages are also > > output in Chinese.] > > > > What happens with the release version is an error message: > > "R for Windows GUI front-end has encountered a problem and needs to > close. We > > are sorry for the inconvenience." Then it offers to "Please tell > Microsoft > > about the problem", and if you "click here" the error signature has: > > AppName: rgui.exe AppVer: 2.40.39566.0ModName: r.dll > > ModVer: 2.40.39566.0 Offset: 000f22b3 > > > > There is a lot more information as well, but I don't know how much is > > relevant. > > > > By "Simplified Chinese set as the locale" I mean 'Control Panel/Regional > and > > Language Options' with Chinese (PRC) set in 'Regional Options/Standards > and > > Formats' and 'Advanced/Language for non-Unicode Programs'. > > > > [I don't rely on the Chinese environment, so this doesn't materially > affect > > me, but I may be able to help with diagnosis.] > > Could you take a look in RHOME/modules at the file iconv.dll? We > upgraded it to version 1.11.0.0 relatively late in the cycle; it's > possible that your successful install uses a different version. (The > version should be available in the popup if you hover the mouse over it, > or in the properties if you right click it.) > > If that's not it, then I'd guess the problem is that the installer > missed some file(s); could you compare the installed file lists from the > beta and the release, and send me a list of files that occur only in the > beta? It's normal for that list to be fairly long, because when you > build yourself a lot of unnecessary files are left behind. > > Duncan Murdoch > -- »ÆÈÙ¹ó Department of Sociology Fudan University [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Possible bug?
This morning I downloaded R-2.4.0 and install in under Windows. I customized the installation and choose "Message translations",but I could not launch Rgui.exe successfully( Rterm.exe worked fine). If I did't choose "Message translations", Rgui.exe worked fine. "Message translations" is Simplified Chinese. > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 4.0 year 2006 month 10 day03 svn rev39566 language R version.string R version 2.4.0 (2006-10-03) -- »ÆÈÙ¹ó Department of Sociology Fudan University [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Voung test implementation in R
Yes, the pscl package contains that function. library(pscl) ?vuong Description Compares two models fit to the same data that do not nest via Vuong's non-nested test. Usage vuong(m1, m2, digits = getOption("digits")) On 9/26/06, mirko sanpietrucci <[EMAIL PROTECTED]> wrote: Dear All, I would like to know if the Voung test (Voung; Econometrica, 1989) to compare two non-nested regression models has been implemented in R. Thanks in advance for your assistance, mirko [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 黄荣贵 Department of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Other editor with completion apart from emacs?
JGR support completion. It can runs under Linux,though JGR is more than a editor. On 9/21/06, Rainer M Krug <[EMAIL PROTECTED]> wrote: Hi is there any other editor for Linux, apart from emacs, which has the completion feature (i.e. I enter lib and it offers me among other options "library") Rainer -- Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT) Department of Conservation Ecology and Entomology University of Stellenbosch Matieland 7602 South Africa Tel:+27 - (0)72 808 2975 (w) Fax:+27 - (0)21 808 3304 Cell: +27 - (0)83 9479 042 email: [EMAIL PROTECTED] [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 黄荣贵 Department of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] "fixed effects" transformation
plm function in plm package are for panel data model. library(plm) ?plm 2006/8/24, Eduardo Leoni <[EMAIL PROTECTED]>: Hi - I am doing an analysis using panel data methods, particularly what economists call "fixed effects". It can easily be done in R through the inclusion of factors in an lm formula. However, when the number of groups is excessive (in my case 2000+) it is much more efficient to demean the data by panel. I created this function following Farnsworth (http://cran.r-project.org/doc/contrib/Farnsworth-EconometricsInR.pdf) demean <- function(x,index) { for (i in unique(index)) { for (j in 1:ncol(x)) { x.now <- x[index==i,j] x[index==i,j] <- x.now-mean(x.now,na.rm=TRUE) } } x } it is obvious that there must be a much much more efficient way to do this, though. Any recommendations? thanks, -eduardo __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 黄荣贵 Department of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] coefficients' order in polr()?
you can use _relevel_ to Reorder Levels of Factor. use ?relevel to get more information. 2006/8/16, T Mu <[EMAIL PROTECTED]>: Hi all, I am using polr(). The resulting coefficients of first levels are always 0. What to do if I wnat to get the coefficients of the last level 0. For example, suppose x has 3 levels, 1, 2, 3 probit <- plor(y ~ x, data1, method='probit') will get coefficients of level 2, 3 of x, but I want coefficients of level 1, 2 Thank you, Tian [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 黄荣贵 Department of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] negative binomial lmer
I think you should use glmm.admb. library(glmmADMB) ?glmm.admb glmm.admb package:glmmADMB R Documentation Generalized Linear Mixed Models using AD Model Builder Description: Fits mixed-effects models to count data using Binomial, Poisson or negative binomial response distributions. Zero-inflated versions of Poisson and negative binomial distributions are available. 2006/7/28, Tracy Feldman <[EMAIL PROTECTED]>: To whom it may concern: I have a question about how to appropriately conduct an lmer analysis for negative binomially distributed data. I am using R 2.2.1 on a windows machine. I am trying to conduct an analysis using lmer (for non-normally distributed data and both random and fixed effects) for negative binomially distributed data. To do this, I have been using maximum likelihood, comparing the full model to reduced models (containing all but one effect, for all effects). However, for negative binomially distributed data, I need to estimate the parameter theta. I have been doing this by using a negative binomial glm of the same model (except that all the effects are fixed), and estimating mu as the fitted model like so: model_1 <-glm.nb(y~x1+x2+x3, data = datafilename) mu_1 <- fitted(model_1) theta_1 <- theta.ml(y, mu_1, length(data), limit = 10, eps = .Machine$double.eps^0.25, trace = FALSE) Then, I conduct the lmer, using the estimated theta: model_11 <-lmer(y~x1+x2+(1|x3), family = negative.binomial(theta = theta_1, link = "log"), method = "Laplace") First, I wondered if this sounds like a reasonable method to accomplish my goals. Second, I wondered if the theta I use for reduced models (nested within model_11) should be estimated using a glm.nb with the same combination of variables. For example, should a glm.nb with x1 and x3 only be used to estimate theta for an lmer using x1 and x3? Third, I wish to test for random effects of one categorical variable with 122 categories (effects of individual). For this variable, the glm.nb (for estimating theta) does not work--it gives this error message: Error in get(ctr, mode = "function", envir = parent.frame())(levels(x), : orthogonal polynomials cannot be represented accurately enough for 122 degrees of freedom Is there any way that will allow me to accurately estimate theta using this particular variable (or without it)? Or should I be using a Poisson distribution (lognormal?) instead, given these difficulties? If anyone has advice on how to properly conduct this test (or any references that might tell me in a clear way), I would be very grateful. Also, please let me know if I should provide additional information to make my question clearer. Please respond to me directly, as I am not subscribed to this list. Thank you very much, Tracy S. Feldman Postdoctoral Associate, the Noble Foundation, Ardmore, OK. __ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 黄荣贵 Department of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] names() function and lmer()
lme4 is S4 package.So you should use slotNames to see what slots an object has,and use @ instead of $ to extract the slot you want. library(lme4) Loading required package: Matrix Loading required package: lattice Loading required package: lattice example(lmer) slotNames(fm2) [1] "assign" "frame""terms""flist""Zt" "X" [7] "y""wts" "wrkres" "method" "useScale" "family" [13] "call" "cnames" "nc" "Gp" "XtX" "ZtZ" [19] "ZtX" "Zty" "Xty" "Omega""L""RZX" [25] "RXX" "rZy" "rXy" "devComp" "deviance" "fixef" [31] "ranef""RZXinv" "bVar" "gradComp" "status" [EMAIL PROTECTED] [1] 1.5127787 -40.3739988 -39.1811143 24.5188772 22.9144206 9.2219771 [7] 17.1561300 -7.4517287 0.5786303 34.7680264 -25.7543295 -13.8649853 [13] 4.9159565 20.9290870 3.2586571 -26.4758005 0.9056393 12.4217767 [19] 9.3234692 -8.5991469 -5.3877753 -4.9686374 -3.1939301 -0.3084938 [25] -0.2872083 1.1159883 -10.9059430 8.6275943 1.2806874 6.7563873 [31] -3.0751268 3.5122002 0.8730485 4.9837782 -1.0052909 1.2583989 2006/7/15, A.R. Criswell <[EMAIL PROTECTED]>: Hello All, I would like to retrieve some of the results from the lmer(...) function in library lme4. If I run a model, say fm.1 <- lmer(y ~ 1 + (1 | x), data = dog) and try names(fm.1), I get NULL. Is there anyway to retrieve the information? Thanks __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Department of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] PDF version of Chinese translations of the manual "An Introduction to R"
That's a great news for all Chinese useR. 2006/7/12, Guohui Ding <[EMAIL PROTECTED]>: Dear All, I distributed the HTML style one year ago ( http://www.biosino.org/pages/newhtm/r/schtml and http://www.biosino.org/pages/newhtm/r/tchtml ). Now I polished it, and rewrote it with Latex. You can download it from the URL: http://www.biosino.org/R/R-doc/ ( http://www.biosino.org/R/R-doc/files/R-intro_cn.pdf). Wish it will be useful for Chinese R users. Any suggestion, comment and correction are welcome! -- ADDRESS: Bioinformatics Center, Shanghai Institutes for Biological Sciences, Chinese Academy of Sciences 320 Yueyang Road, Shanghai 200031, P.R.China TELEPHONE: 86-21-54920086 [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Department of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] new object
sum.out<-summary(fit) names(sum.out) [1] "surv" "time" "n.risk" "n.event" "conf.int" "std.err" [7] "lower""upper""strata" "call" sum.out$n.risk [1] 11 10 8 7 5 4 2 12 10 8 6 5 4 3 2 1 sum.out$n.event [1] 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 cbind(sum.out$n.risk,sum.out$n.event,sum.out$strata) [,1] [,2] [,3] [1,] 1111 [2,] 1011 [3,]811 [4,]711 [5,]511 [6,]411 [7,]211 [8,] 1222 [9,] 1022 [10,]812 [11,]612 [12,]512 [13,]412 [14,]312 [15,]212 [16,]112 2006/7/11, Mauricio Cardeal <[EMAIL PROTECTED]>: Hi ! Please, how can I extract n.event and n.risk as a new object from example below ? Thanks in advance. Mauricio require(survival) fit <- survfit(Surv(time, status) ~ x, data=aml) summary(fit) Call: survfit(formula = Surv(time, status) ~ x, data = aml) x=Maintained time n.risk n.event survival std.err lower 95% CI upper 95% CI 9 11 10.909 0.0867 0.75411.000 13 10 10.818 0.1163 0.61921.000 18 8 10.716 0.1397 0.48841.000 23 7 10.614 0.1526 0.37690.999 31 5 10.491 0.1642 0.25490.946 34 4 10.368 0.1627 0.15490.875 48 2 10.184 0.1535 0.03590.944 x=Nonmaintained time n.risk n.event survival std.err lower 95% CI upper 95% CI 5 12 2 0.8333 0.1076 0.64701.000 8 10 2 0.6667 0.1361 0.44680.995 12 8 1 0.5833 0.1423 0.36160.941 23 6 1 0.4861 0.1481 0.26750.883 27 5 1 0.3889 0.1470 0.18540.816 30 4 1 0.2917 0.1387 0.11480.741 33 3 1 0.1944 0.1219 0.05690.664 43 2 1 0.0972 0.0919 0.01530.620 45 1 1 0. NA NA NA [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Department of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] about overdispersed poisson model
You can use glm to analysis this data ,with family=quasipoisson. see ?glm and ?family 2006/7/10, g0354502 <[EMAIL PROTECTED]>: Dear R users I have been looking for functions that can deal with overdispersed poisson models. According to actuarial literature (England & Verall, Stochastic Claims Reserving in General Insurance , Institute of Actiuaries 2002) this can be handled through the use of quasi likelihoods instead of normal likelihoods. However, we see them frequently in this type of data, and we would like to be able to fit the model anyway. If it is possible, would you please show me how to find the corresponding package and utilize them? Best Regards, Chi Kai __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Department of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to name a variable?
s<-data.frame(var.name=seq(1,6,by=2)) s var.name 11 23 35 2006/7/7, zhijie zhang <[EMAIL PROTECTED]>: Dear friends, The "s" in the following argument don't have a variable name, how should i give it a name? > s<-data.frame(seq(1,6,by=2)) > s seq.1..6..by...2. 1 1 2 3 3 5 thanks very much! -- Kind Regards, Zhi Jie,Zhang ,PHD Department of Epidemiology School of Public Health Fudan University Tel:86-21-54237149 [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Department of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Data Manipulations - Group By equivalent
use doBy package will be more easy. # GENERATE A TREATMENT GROUP # group<-as.factor(paste("treatment", rep(1:2, 4), sep = '_')); # CREATE A SERIES OF RANDOM VALUES # x<-rnorm(length(group)); # CREATE A DATA FRAME TO COMBINE THE ABOVE TWO # data<-data.frame(group, x); library(doBy) summ2<-summaryBy(x~group,data=data,FUN=c(mean,sum),na.rm=T,prefix=c("mean","sum")) combine2<-merge(data,summ) Ronggui 2006/7/2, Wensui Liu <[EMAIL PROTECTED]>: Zubin, I bet you are working for intercontinental hotels and think you probably are not the real Zubin there. right? ^_^. If you have chance, could you please say hi to him for me? Here is a piece of R code I copy from my blog side by side with SAS. You might need to tweak it a little to get what you need. CALCULATE GROUP SUMMARY IN R ## # HOW TO CALCULATE GROUP SUMMARY IN R # # DATE : DEC-13, 2005 # ## # EQUIVALENT SAS CODE: # # # # DATA DATA; # # DO I = 1 TO 2; # # DO J = 1 TO 4; # # GROUP = 'TREATMENT_'||PUT(I, 1.); # # X = RANNOR(1); # # OUTPUT; # # END; # # END; # # KEEP GROUP X; # # RUN; # # # # PROC SQL; # # CREATE TABLE COMBINE AS # # SELECT *, MEAN(X) AS MEAN_X, SUM(X) AS SUM_X # # FROM DATA # # GROUP BY GROUP; # # QUIT; # ## # GENERATE A TREATMENT GROUP # group<-as.factor(paste("treatment", rep(1:2, 4), sep = '_')); # CREATE A SERIES OF RANDOM VALUES # x<-rnorm(length(group)); # CREATE A DATA FRAME TO COMBINE THE ABOVE TWO # data<-data.frame(group, x); # CALCULATE SUMMARY FOR X # x.mean<-tapply(data$x, data$group, mean, na.rm = T); x.sum<-tapply(data$x, data$group, sum, na.rm = T); # CREATE A DATA FRAME TO COMBINE SUMMARIES # summ<-data.frame(x.mean, x.sum, group = names(x.mean)); # COMBINE DATA AND SUMMARIES TOGETHER # combine<-merge(data, summ, by = "group"); On 7/1/06, zubin <[EMAIL PROTECTED]> wrote: > > Hello, a beginner R user - boy i wish there was a book on just data > manipulations for SAS users learning R (equivalent to the SAS DATA > STEP).. Okay, my question: > > I have a panel data set, hotel data occupancy by month for 12 months, > 1000 hotels. I have a field labeled 'year' and want to consolidate the > monthly records using an average into 1000 occupancy numbers - just a > simple average of the 12 months by hotel. In SQL this operation is > pretty easy, a group by query (group by hotel where year = 2005, avg > occupancy) - how is this done in R? (in R language not SQL). Thx! > > -zubin > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > -- WenSui Liu (http://spaces.msn.com/statcompute/blog) Senior Decision Support Analyst Health Policy and Clinical Effectiveness Cincinnati Children Hospital Medical Center [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Department of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to recode in my dataset?
I always use "recode" function (in the car packages) to recode variables.That works well and I like that function. 2006/7/2, zhijie zhang <[EMAIL PROTECTED]>: Dear Rusers, My question is about "recode variables". First, i'd like to say something about the idea of recoding: My dataset have three variables:type,soiltem and airtem,which means grass type, soil temperature and air temperature. As we all known, the change of air temperature is greater than soil temperature,so the values in those two different temperaturemay represent different range. My recoding is to recode soiltem with 0.2 intervals, and airtem with 0.5 intervals, that is: In soiltem:0~0.2<-0.1, 0.2~0.4<-0.3, 0.4`0.6<-0.5,...etc; In airtem:0~0.5<-0.25, 0.5~1<-0.75, 1`1.5<-1.25,...etc; My example like this: type<-c(1, 1, 2, 3,4,1,1,4,3,2) soiltem<-c(19.2,18.6,19.5,19.8,19.6,20.6,19.1,18.7,22.4,21.6) airtem<-c(19.9,20.5,21.6,25.6,22.6,21.3,23.7,21.5,24.7,24.4) mydata<-data.frame(type,soiltem,airtem) #copy the above four arguments to generate the dataset mydata type soiltem airtem 1 119.2 19.9 2 118.6 20.5 3 219.5 21.6 4 319.8 25.6 5 419.6 22.6 6 120.6 21.3 7 119.1 23.7 8 418.7 21.5 9 322.4 24.7 10221.6 24.4 Thanks very much! -- Kind Regards, Zhi Jie,Zhang ,PHD Department of Epidemiology School of Public Health Fudan University Tel:86-21-54237149 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Department of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to get the studentized residuals in lm()
help.search("studentized") You will see: studres(MASS) Extract Studentized Residuals from a Linear Model 2006/7/3, zhijie zhang <[EMAIL PROTECTED]>: Dear friends, In s-plus, lm() generates the the studentized residuals automatically for us, and In R, it seems don't have the results: After i fitted lm(), i use attibutes() to see the objects and didn't find studentized residuals . How to get the the studentized residuals in lm(),have i missed something? thanks very much! -- Kind Regards, Zhi Jie,Zhang ,PHD Department of Epidemiology School of Public Health Fudan University Tel:86-21-54237149 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Department of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] programming advice
Will the following code work for you? index<-!(x==0 & y==0) x<-x[index] y<-y[index] 2006/6/22, Fred JEAN <[EMAIL PROTECTED]>: Dear R users I want to compute Kendall's Tau between two vectors x and y. But x and y may have zeros in the same position(s) and I wrote the following function to be sure to drop out those "double zeros" "cor.kendall" <- function(x,y) { nox <- c() noy <- c() # for (i in 1:length(x)) if (x[i]!= 0 | y[i] != 0) nox[length(nox)+1]<- x[i] for (i in 1:length(y)) if (x[i]!= 0 | y[i] != 0) noy[length(noy)+1]<- y[i] # res.kendall <- cor.test(nox,noy,method = "kendall",exact=F) return(list(x=nox,y=noy,res.kendall,length(nox))) } Do you know a more elegant way to achieve the same goal ? (I'm sure you do : it's a newbie's program actually) -- Fred __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Department of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] eliminating a do loop
Have you tried these: png() lapply(simint.by.fit,plot) dev.off() 2006/6/22, Barker, Chris [SCIUS] <[EMAIL PROTECTED]>: Using a "by() statement, I am preparing ANOVA's for multiple experiments, and using simint() to generate confidence intervals. This works fine. simint.by.fit <- by(analytes.dfr, list(Assay = analytes.dfr$analyte ), function(data) (simint(value ~ tx, data = data,type='Tukey' ) ) ) I can separately prepare plots of the confidence intervals, and I can prepare separate plots or use for/do loop e.g. plot( simint.by.fit$"Assay 1" ) plot( simint.by.fit$"Assay 2") Is there a way to generate and save multiple -separate- plots without using a do loop, e.g. using lapply?. I tried a couple variations using lapply, lapply(simint.by.fit,plot) not surprising, I only get the last plot, the other plots seem to get overwritten. Thanks in advance [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Department of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] xyplot, type="b"
apropos("^panel") will show you what panel function exist.It seems that panel.points plus panel.lines are what you want. dat<-data.frame(x=1:10,y=1:10,z=sample(letters[1:3],10,T)) xyplot(y~x | z, data = dat,pan=function(x,y,...) {panel.points(x,y,...);panel.lines(x,y,...)}) 2006/6/21, Benjamin Tyner <[EMAIL PROTECTED]>: Is there any way to have xyplot produce the "points connected by lines" analogous to the effect of type="b" under standard graphics? I seem to recall doing this in xyplot at one point. Thanks, Ben __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Department of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Extract information from the summary of 'lm'
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69) group <- gl(2,10,20, labels=c("Ctl","Trt")) weight <- c(ctl, trt) lm.D9 <- lm(weight ~ group) summary(lm.D9)$coef Estimate Std. Error t value Pr(>|t|) (Intercept)5.032 0.2202177 22.850117 9.547128e-15 groupTrt -0.371 0.3114349 -1.191260 2.490232e-01 class(summary(lm.D9)$coef) [1] "matrix" > colnames(summary(lm.D9)$coef) [1] "Estimate" "Std. Error" "t value""Pr(>|t|)" So you can get t and p-value by >summary(lm.D9)$coef[,"t value"] summary(lm.D9)$coef[,"Pr(>|t|)"] If you want to get the result as matrix,just use the drop=F argument. summary(lm.D9)$coef[,"Pr(>|t|)",drop=F] Pr(>|t|) (Intercept) 9.547128e-15 groupTrt2.490232e-01 2006/6/21, Jun Ding <[EMAIL PROTECTED]>: Hi Everyone, I just don't know how to extract the information I want from the summary of a linear regression model fitting. For example, I fit the following simple linear regression model: results = lm(y_var ~ x_var) summary(results) gives me: Call: lm(formula = y_var ~ x_var) Residuals: Min 1Q Median 3Q Max -5.9859 -1.5849 0.4574 2.0163 4.6015 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -1.7782 0.5948 -2.990 0.004879 ** x_var 2.1237 0.5073 4.187 0.000162 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 I can get the esitmates (i.e. -1.7782 and 2.1237) of coefficients by calling results$coefficients I think using coef(result) is a better habit. But I don't know how to get the corresponding t values and P values for those coefficients. I am running a lot of regression models and I can not run 'summary' every time to get the t and P values for each model. Can anybody give me some hints? Thank you very much! Best, Jun Jun Ding, Ph.D. student Department of Biostatistics University of Michigan Ann Arbor, MI, 48105 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Department of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Method for selection bias with multinomial treatment
I have to the treatment effect base on the observational data.And the treatment variable is multinomial rather than binary.Because the treatment assignment is not random,so the selection-bias exists.Under this condition,what's the best way to estimate the treatment effect? I know that if the treatment is binary,I can use propensity score matching using MatchIt package.But what about multinomial? Maybe one way is the method proposed by Imbens,2000,The role of the propensity score in estimating dose-response functions,Biometrika,87:706-710.But I can't find any R function to do the task.So I hope the lister can give me some suggestions. Thank you in advance! -- 黄荣贵 Department of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] set.seed
set.seed is used to set the random number seed. When we use functions ,say runif, to generate random number ,we almost get different set of random number. runif(5) [1] 0.2096388 0.3427873 0.5455948 0.7694844 0.4287647 runif(5) [1] 0.6864617 0.5218690 0.7965364 0.9030520 0.4324572 But in some cases,we want the results reproducible.so we use set.seed before generate the number. set.seed(100) runif(5) [1] 0.30776611 0.25767250 0.55232243 0.05638315 0.46854928 set.seed(100) runif(5) [1] 0.30776611 0.25767250 0.55232243 0.05638315 0.46854928 So if you set the same random number seed before you generate the number,you get the same result.(That's why we call it pesudo-random number.) As for what the i in set.seed(i) should be,I don't think it is a serious matter. 2006/6/14, Xiaohua Dai <[EMAIL PROTECTED]>: Hi R users, Sorry for a simple question: I found different people use different i in set.seed(i), are there any rules to choose an i or one can choose as he likes? Thanks Xiaohua __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] could someone tell me how to implement a multiple comparison test for proportions in a 2xc crosstabulation
?p.adjust It's the function used to Adjust P-values for Multiple Comparisons. 2006/6/14, xingwang ye <[EMAIL PROTECTED]>: Dear all, I wanna to do multiple comparison test for proportions (multiple chi squre ?), could someone tell me how in R, thank you! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] [Fwd: R 2.20 Windows XP anaolgue of Splus unix() command ?]
In my windows XP there is no "read" command as well,so the _ unix("read stuff")_ will not wor as what _system_ function does is to pass the 'read stuff' command argument to the system command. I guess the "read" command to specific to some Unix OS. Hope this helps. 2006/6/9, [EMAIL PROTECTED] <[EMAIL PROTECTED]>: >Hi Everyone : As I mentioned earlier, I am taking a lot >of Splus code and turning into R and I've run into >another stumbling block that I have not been >able to figure out. > >I did plotting in a loop when I was using Splus on unix >and the way I made the plots stop so I could >lookat them as they got plotted ( there are hundreds >if not thousands getting plotted sequentially ) >on the screen was by using the unix() command. > >Basically, I wrote a function called wait() > > >wait<-function() >{ >cat("press return to continue") >unix("read stuff") >} > >and this worked nicely because I then >did source("program name") at the Splus prompt and >a plot was created on the screen and then >the wait() function was right under the plotting code >in the program so that you had to hit the return key to go to the next plot. > >I am trying to do the equivalent on R 2.20/windows XP >I did a ?unix in R and it came back with system() and >said unix was deprecated so I replaced unix("read stuff") with system("read stuff") but all i get is a warning "read not found" and >it flies through the successive plots and i can't see them. > >Thanks for any help on this. It's much appreciated. > >Mark __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to request AIC information from "lm" object?
You can use AIC to get what you want. #example from lm help page ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69) group <- gl(2,10,20, labels=c("Ctl","Trt")) weight <- c(ctl, trt) anova(lm.D9 <- lm(weight ~ group)) Analysis of Variance Table Response: weight Df Sum Sq Mean Sq F value Pr(>F) group 1 0.6882 0.6882 1.4191 0.249 Residuals 18 8.7293 0.4850 #get the AIC of lm model. AIC(lm.D9) [1] 46.17648 2006/6/9, Michael <[EMAIL PROTECTED]>: Can "lm" return AIC information? Thanks a lot! [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] JGR :: Can't Run Graphics Demo
Have you installed the following packages?They are javaGD,rJava,iplots,iWidgets? It seems that you have installed the javaGD package. 2006/6/8, Alex Restrepo <[EMAIL PROTECTED]>: Hello: I am using JGR 1.4, the Java GUI for R and I am trying to run the demo for graphics using the command: demo(graphics) I keep on getting the following errror: Error in get(getOption("device"))() : unable to start device JavaGD FYI, the version of Java I am using is: 1.5.0_07-b03 Do I need to use a different version of Java? Does anyone have any recommendations/suggestions? Many Thanks In Advance: Alex __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Edit function
If you want to change the data,_fix_ will be a good option.But if you just want to browse the data ,then invisible(edit(data)) is better one. I remember this question showed up some time ago. 2006/6/7, Ulrich Keller <[EMAIL PROTECTED]>: > fix(data) > > will invoke edit(data) and store changes you make in data without > displaying anything. > > stat stat schrieb: > > Dear all R users, > > > > I have a query on "Edit" function. Suppose I have a data frame named > > "data". I can use EDIT function to see the materials contained in data, by > > using the command: > > > > > edit(data) > > > > But when I close the window then again the materials contained in data is > > displayed in the command window. But I do not want to see these materials > > again. Can anyone give me any idea on how to do this? > > > > Thanks and regards, > > stat > > > > Send instant messages to your online friends http://in.messenger.yahoo.com > > > > Stay connected with your friends even when away from PC. Link: > > http://in.mobile.yahoo.com/new/messenger/ > > [[alternative HTML version deleted]] > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > > > > > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- ronggui huang Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Can lmer() fit a multilevel model embedded in a regression?
I don't answser your question directly.I juset point out that Rnews 2005-1 has an article about lmer :Fitting linear mixed models in R Using the lme4 package by the author of the package Matrix.The article says "lmer handles nested and non-nested grouping factors equally easily". Hope This helps. 2006/5/20, Andrew Gelman <[EMAIL PROTECTED]>: I would like to fit a hierarchical regression model from Witte et al. (1994; see reference below). It's a logistic regression of a health outcome on quntities of food intake; the linear predictor has the form, X*beta + W*gamma, where X is a matrix of consumption of 82 foods (i.e., the rows of X represent people in the study, the columns represent different foods, and X_ij is the amount of food j eaten by person i); and W is a matrix of some other predictors (sex, age, ...). The second stage of the model is a regression of X on some food-level predictors. Is it possible to fit this model in (the current version of) lmer()? The challenge is that the persons are _not_ nested within food items, so it is not a simple multilevel structure. We're planning to write a Gibbs sampler and fit the model directly, but it would be convenient to be able to flt in lmer() as well to check. Andrew --- Reference: Witte, J. S., Greenland, S., Hale, R. W., and Bird, C. L. (1994). Hierarchical regression analysis applied to a study of multiple dietary exposures and breast cancer. Epidemiology 5, 612-621. -- Andrew Gelman Professor, Department of Statistics Professor, Department of Political Science [EMAIL PROTECTED] www.stat.columbia.edu/~gelman Statistics department office: Social Work Bldg (Amsterdam Ave at 122 St), Room 1016 212-851-2142 Political Science department office: International Affairs Bldg (Amsterdam Ave at 118 St), Room 731 212-854-7075 Mailing address: 1255 Amsterdam Ave, Room 1016 Columbia University New York, NY 10027-5904 212-851-2142 (fax) 212-851-2164 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Please help me to combine two datasets.
?merge maybe is what you want. 2006/5/11, Arun Kumar Saha <[EMAIL PROTECTED]>: Dear r-users, Suppose I have two data sets data set-1 Date height 1/11/2005 10 2/11/2005 23 3/11/2005 54 4/11/2005 21 5/11/2005 22 data set-2 weight 32 45 11 Now I want to combine this two data sets. i.e. i want to see: Date height weight --- 3/11/2005 54 32 4/11/2005 21 45 5/11/2005 22 11 Can any one give me the required r-code to perform this? Thanks and regards, Arun [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] A question about encoding
I use R 2.3.0 under windows. Sys.getlocale() [1] "LC_COLLATE=Chinese_People's Republic of China.936;LC_CTYPE=Chinese_People's Republic of China.936;LC_MONETARY=Chinese_People's Republic of China.936;LC_NUMERIC=C;LC_TIME=Chinese_People's Republic of China.936" localeToCharset() [1] "CP936" Now I want to use JGR,which uses UTF-8 encoding. So when I use save.image function to save something containg Chinese character with R,and then load into JGR, the Chinese character will not display correctly.Of course,I can use iconv to convert the character making it readable.But is there any better way to this? Thanks. -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] read.table (Error in file(file, "r") : unable to open connection)
I guess you use R under windows,then use \\ instead of \. or use file.choose() to choose the file directly. 2006/5/9, [EMAIL PROTECTED] <[EMAIL PROTECTED]>: > G'day, > > I am trying to read in a table and am getting an error message stating that R > is unable to open a connection to the file. > > ➢ Avonvegen<- read.table("Y:\Study > Sites\Avon\nonspatial\datafiles\archive\Avon_VegEnh.dat ", sep=",", > na.string="-", header=TRUE) > Error in file(file, "r") : unable to open connection > In addition: Warning message: > cannot open file 'Y:Study SitesAvon > onspatialdatafilesrchiveAvon_VegEnh.dat ', reason 'Invalid argument' > > > > I have checked that the AvonVegEnh.dat is spelt correctly and has no hidden > extensions. > I have checked that the folder is accessible. > I have moved the datafile and changed the script to try reading from the > local drive with no success. > > I have used the same syntax on a similar file (same field structure but > different data) with no problems before and now it doesn't read either. > > Does anyone have any ideas? > > Thanks, > david > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Panel Data Estimators (within, between, Random Effects estimator)
Some time ago,I wrote some simple functions to do the fixed/between/random effects regression.If you want the code,pls drop me a line. 2006/5/8, David STADELMANN <[EMAIL PROTECTED]>: Dear R Users, Here is another probelm/question. I would like to run some panel regressions with R. Therefore I have combined several time periods of data for different individuals in my database. I have already run pooled OLS but I would need to calculate a Fixed Effects Estimator (within estimator). Unfortunately I couldn't find anything like that in the RSearch and I suppose that lme (in package nlme) is not the answer. Is there any defined function to calculate panel data estimators like Fixed Effects Estimators (within), a between estimator or a Random Effects estimator. For more details on the estimators I would like to use see: Cameron, A. C.; Trivedi, P. K.: "Microeconometrics. Methods and Applications", Cambridge University Press, 2005, pp. 695-809. One way to get the fixed effects estimator is using dummy regression by adding factor(id) in the right side to the formula.(the id is panel ID variable).Just be aware that the R-sqare from dummy regression is overestimated.If I remember correctly,you can get the R-sqare by calculate the square of the correlation between response variable and the predicted value. And package nlme can do the random effects by ML/REML methods.(Maybe not axactly what you want).This is achieved by gls function by specifying the cor argument. The following example is from Wooldrige(1999),Introductory Econometrics. summary(gls(lwage~educ+black+hisp+exper+expersq+married+union,cor=corCompSymm(form=~1|nr),data=wagepan,method="ML")) It is the same as the Stata command: xtreg lwage educ black hisp exper expersq married union,i(nr) mle I hope it helps. Thanks for your help. David Stadelmann -- ## David Stadelmann Seminar für Finanzwissenschaft Université de Fribourg Bureau F410 Bd de Pérolles 90 CH-1700 Fribourg SCHWEIZ Tel: +41 (026) 300 93 82 Fax: +41 (026) 300 96 78 Tel (priv): +41 (044) 586 78 99 Mob (priv): +41 (076) 542 33 48 Email: [EMAIL PROTECTED] Internet: http://www.unifr.ch/finwiss Internet (priv): http://david.stadelmann-online.com __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Math expressions in pie chart labels?
Then please read ?plotmath and use it: labels = expression("" >= 0.66, "" == 0.33, "" <= -0.33, "" <= -0.66) pie(1:3,lab="") text(locator(3),lab=expression("">=1,""=2,""<=3)) Error: attempt to use zero-length variable name text(locator(3),lab=expression(NULL>=1,NULL=2,NULL<=3)) What 's the problem come from? It seems that NULL>=something is prefered to "">=something,isn't it? version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 3.0 year 2006 month 04 day24 svn rev37909 language R version.string Version 2.3.0 (2006-04-24) > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to strip of a term in data.frame
2006/5/3, Guojun Zhu <[EMAIL PROTECTED]>: say I have 100 terms for data.frame a. I want to do a linear regression of one term (say y) on other 33 terms. the only way to write this is "lm(y~., data=a)". But there are some intermediate term on a and I need to take them off before I can run it. I know you can use a[,-(3:4)], But can I specify it by name instead, I want to save everything in a script, something by name is much easier to read and easier to maintain later. Here is one way: suppose the variables you want to remove are c("x","y","z"),then you can use match to get the posistion index.so the following code will work. a.new <- a[,-match(c("x","y","z"),names(a))] also, how to take of some rows from data.frame. For example every row year==1995 or something like that? _subset_ will do the job,for example a.sub <- subset(a,year==1995) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Math expressions in pie chart labels?
I think you should use labels = c(">= 0.66", ">= 0.33", "<= -0.33", "<= -0.66") . Note the quote in each element of the vector. 2006/5/3, Johannes Graumann <[EMAIL PROTECTED]>: Hello, trying to get something like this to work and am failing: pie( c(length(strongN14),length(weakN14),length(weakN15),length(strongN15),length(ambiguous)), labels = c(>= 0.66, >= 0.33, <= -0.33, <= -0.66), col = c("#FF","#CC","#009900","lightgreen","white") ) Can't figure out a way to display the 'greater or equal' ... signs properly. I'm thankful for any prodding into the right direction. Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Where do I find Cohen´s kappa???
kappa(base) is used to Estimate the Condition Number,so it is NOT what you want. And several packages have function related to your question: cohen.kappa(concord)kappa reliability coefficient for nominal data kappa2(irr) Cohen's Kappa and weighted Kappa for two raters ckappa(psy) Cohen's Kappa for 2 raters Kappa(vcd) Cohen's Kappa and Weighted Kappa Hope this helps:) 2006/4/29, jones christian <[EMAIL PROTECTED]>: > Hello, > I´m looking for a way to measure the goodness of fit of my model with Cohen´s > Kappa (scaling between 0 and 1). > The kappa function does not give the results I´m looking for. Heres the code: > z<-glm(x~y,binomial) > kappa(z, exact = T) > Does anyone know more? > > many thanks > Christian > > -- > ___ > > Search for businesses by name, location, or phone number. -Lycos Yellow Pages > > http://r.lycos.com/r/yp_emailfooter/http://yellowpages.lycos.com/default.asp?SRC=lycos10 > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] stepwise regression
在 06-4-28,Jinsong Zhao<[EMAIL PROTECTED]> 写道: Dear all, I have encountered a problem when perform stepwise regression. The dataset have more 9 independent variables, but 7 observation. ~I think this is the problem. In R, before performing stepwise, a lm object should be given. fm <- lm(y ~ X1 + X2 + X3 + X11 + X22 + X33 + X12 + X13 + X23) However, summary(fm) will give: Residual standard error: NaN on 0 degrees of freedom Multiple R-Squared: 1, Adjusted R-squared: NaN F-statistic: NaN on 6 and 0 DF, p-value: NA In this situation, step() or stepAIC() will not give any useful information. I don't know why SAS could deal with this situation: PROC REG; MODEL y=X1 X2 X3 X11 X22 X33 X12 X13 X23/SELECTION=STEPWISE; RUN; Any help will be really appreciated. Wishes, Jinsong Zhao __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] plot cdf
I think curve is one option. for example , I can use "curve(pnorm,-5,5)" to plot the normal cdf. use ?curve to get the usage. 2006/4/27, Nongluck Klibbua <[EMAIL PROTECTED]>: > hi, > I would like to know what is the function to plot cdf. > Thanks, > Luck > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] there is no "xls" reader in R?
Read the manual _R Data Import/Export_ which is shipped with R.The section "8 Reading Excel spreadsheets" will tell what you want. 2006/4/20, Michael <[EMAIL PROTECTED]>: > Currently I have to convert all my "xls" into "csv" before I can read it in > and process the excel data in R... > > Is there a way to directly read in "xls" data? > > Thanks a lot! > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to do varimax rotation for principal component based factor analysis, any packages?
I don't think the result from _princomp _ should be rotated. The definition of "principal components" explicitly indicates that the result is to have axes that are uncorrelated and line up in directions of maximum variance. If I am wrong,I hope some one else to point it out. 2006/4/16, Yong Wang <[EMAIL PROTECTED]>: > Dear R users > the factanal pacakge is always MLE, which package can do varimax > rotation with the results from princomp ? > > thank you > > yong > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to count the columns of a data.frame
> da<-data.frame(x=rnorm(10),y=rnorm(10)) > ncol(da) [1] 2 or > dim(da)[2] [1] 2 2006/4/15, giacomo moro <[EMAIL PROTECTED]>: > Hi, > I would like to count the columns of a data.frame. I know how to count the > rows, but not the columns. > Can someone tell me how to do it? > My best regards, > Giacomo Moro > > > > - > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] The object argument of NextMethod.
在 06-4-14,Gabor Grothendieck<[EMAIL PROTECTED]> 写道: > In section 5.5 of the language manual it says: > > "It is important to realize that the choice of the next method depends on the > current values of .Generic and .Class and not on the object. So changing > the object in a call to NextMethod affects the arguments received by > the next method but does not affect the choice of the next method." Can anyone give an example to demostrated "affects the arguments received by the next method"?In my example NextMethod("foo") and NextMethod("foo",x) give the same result too. > foo=function(x) {UseMethod("foo")} > > foo.cls1=function(x) + { + x=x+1 + NextMethod("foo") + } > > foo.ncls=function(x) + { + cat("ncls\n") + } > > foo.cls2=function(x) + { + cat("cls2\n");print(x) + } > > a=1;class(a)=c("cls1","cls2") > > foo(a) cls2 [1] 2 attr(,"class") [1] "cls1" "cls2" > foo=function(x) {UseMethod("foo")} > > foo.cls1=function(x) + { + x=x+1 + NextMethod("foo",x) + } > > foo.ncls=function(x) + { + cat("ncls\n") + } > > foo.cls2=function(x) + { + cat("cls2\n");print(x) + } > > a=1;class(a)=c("cls1","cls2") > > foo(a) cls2 [1] 2 attr(,"class") [1] "cls1" "cls2" > I think this needs to be put into ?NextMethod too since the current > wording in ?NextMethod appears to contract the language manual: > > "object: an object whose class will determine the method to be > dispatched. Defaults to the first argument of the enclosing > function." > > At any rate, try using .Class to direct it to the appropriate method like > this: > > > foo <- function(x) UseMethod("foo") > > foo.cls1 <- function(x) { x <- x+1; .Class <- class(x) <- "ncls"; > > NextMethod() } > > foo.ncls <- function(x) cat("ncls\n") > > foo.cls2=function(x) { cat("cls2\n"); print(x) } > > a <- 1; class(a) <- c("cls1","cls2") > > > > foo(a) > ncls > > On 4/14/06, ronggui <[EMAIL PROTECTED]> wrote: > > My question is when the object argument of NexthMethod be used? > > > > In the following example, weather object argument is used will not > > affects the result. > > > > ### > > foo=function(x) {UseMethod("foo")} > > > > foo.cls1=function(x) > > { > > x=x+1;class(x)<-"ncls" > > NextMethod() > > } > > > > foo.ncls=function(x) > > { > > cat("ncls\n") > > } > > > > foo.cls2=function(x) > > { > > cat("cls2\n");print(x) > > } > > > > a=1;class(a)=c("cls1","cls2") > > > > > foo(a) > > cls2 > > [1] 2 > > attr(,"class") > > [1] "ncls" > > > > ### > > > foo=function(x) {UseMethod("foo")} > > > > > > foo.cls1=function(x) > > + { > > + x=x+1;class(x)<-"ncls" > > + NextMethod(,x) > > + } > > > > > > foo.ncls=function(x) > > + { > > + cat("ncls\n") > > + } > > > > > > foo.cls2=function(x) > > + { > > + cat("cls2\n");print(x) > > + } > > > > > > a=1;class(a)=c("cls1","cls2") > > > > > > foo(a) > > cls2 > > [1] 2 > > attr(,"class") > > [1] "ncls" > > > > Thank you very much. > > > > -- > > 黄荣贵 > > Deparment of Sociology > > Fudan University > > > > > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > > > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] The object argument of NextMethod.
My question is when the object argument of NexthMethod be used? In the following example, weather object argument is used will not affects the result. ### foo=function(x) {UseMethod("foo")} foo.cls1=function(x) { x=x+1;class(x)<-"ncls" NextMethod() } foo.ncls=function(x) { cat("ncls\n") } foo.cls2=function(x) { cat("cls2\n");print(x) } a=1;class(a)=c("cls1","cls2") > foo(a) cls2 [1] 2 attr(,"class") [1] "ncls" ### > foo=function(x) {UseMethod("foo")} > > foo.cls1=function(x) + { + x=x+1;class(x)<-"ncls" + NextMethod(,x) + } > > foo.ncls=function(x) + { + cat("ncls\n") + } > > foo.cls2=function(x) + { + cat("cls2\n");print(x) + } > > a=1;class(a)=c("cls1","cls2") > > foo(a) cls2 [1] 2 attr(,"class") [1] "ncls" Thank you very much. -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] subset a matrix
> x=matrix(rnorm(20*30),20) > y=x[seq(1,20,by=2),seq(1,30,by=2)] 2006/4/12, zhijie zhang <[EMAIL PROTECTED]>: > Dear friends, > I have a (20*30) matrix,and want to get a subset of it like the following: > The original matrix: rows:1,2,3,20; columns:1,2,3,30 > I want to get my subset of The original matrix and delete others: >rows:1,3,5,7,...19; columns:1,3,5.29 > > > -- > Kind Regards,Zhi Jie,Zhang ,PHDDepartment of EpidemiologySchool of Public > HealthFudan UniversityTel:86-21-54237149 > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Error with 'var' in JGR
It works well for me. > x<-rnorm(50) > var(x) [1] 0.6998658 > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major2 minor2.1 year 2005 month12 day 20 svn rev 36812 language R JRG:1.3 version 2006/4/12, Bret Collier <[EMAIL PROTECTED]>: > R-Users, > I had a strange occurrence this AM I could use some help with. 'var' seems > to have ceased to work for me when I used JGR 1.3 interface. So, I ran a > quick test (following pg 57 of Dalgaard) in both the basic RGui and JGR > interface (see below). I have re-installed R 2.2.1 and JGR 1.3 but had no > luck so far figuring this out? Anyone have a suggestion? Or did I just make > a mistake somewhere (which is more than likely). > > Thanks, > Bret > TX A&M > > > Output from RGui: > > > x<-rnorm(50) > > x > [1] -1.016219752 0.940801964 0.168647573 0.328696253 -0.600957761 > [6] -0.420394338 -1.140567123 -0.755041336 0.907831188 0.198247025 > [11] -0.065116449 0.732841048 -0.400194138 -1.490167845 -1.488611328 > [16] 0.311665408 -1.534002497 -1.094357124 -1.717282302 0.217445299 > [21] -1.878605987 -0.214200092 -0.096099830 -0.357325121 -0.118191356 > [26] -0.214543361 -0.399768989 0.235104678 -0.363194200 -0.275338828 > [31] -0.336677033 -0.009178995 1.294139880 1.442454681 1.192023689 > [36] -0.521847342 -1.070860356 -0.756584142 0.747503883 0.939960584 > [41] -1.444890590 1.218499328 0.343071542 1.303250666 -0.603718755 > [46] 0.979527031 -3.709878278 -0.051090815 -0.452191654 -0.206564681 > > mean(x) > [1] -0.226039 > > sd(x) > [1] 0.9917835 > > var(x) > [1] 0.9836345 > > > Output from JGR: > > > x<-rnorm(50) > > x > [1] 0.79961648 -0.72223557 -0.10589876 > [4] -0.25367834 -0.53518039 0.18296671 > [7] 0.33981503 0.29208966 1.15002574 > [10] 0.84356083 -0.87841050 0.31345819 > [13] 0.61348608 1.13257372 -0.14366714 > [16] -1.28563266 1.39519683 -0.85124979 > [19] -1.65043342 0.93956978 1.36692691 > [22] 0.81240164 -0.44326482 0.20741846 > [25] 0.38536713 -0.57994109 1.10457148 > [28] -0.99307813 -2.31580515 -1.61582072 > [31] 1.63273805 -1.49289425 -1.33675463 > [34] -1.17789478 -0.42209334 -0.21208394 > [37] -2.21572873 0.35724725 -0.24758106 > [40] 0.60470892 1.71646244 1.02161560 > [43] 2.93773901 -0.92356017 -0.38588476 > [46] -0.08622336 -0.09622387 -0.91419002 > [49] 0.93453732 -0.25280526 > > mean(x) > [1] -0.02108243 > > sd(x) > [1] 1.077132 > > var(x) > Error in get(x, envir, mode, inherits) : variable "var" was not found > > > >version > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major2 > minor2.1 > year 2005 > month12 > day 20 > svn rev 36812 > language R > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to figure out "skewness"
you can transform the variable x "down the ladder" if it is positive skew (x^0.5,x^ -1...)and "up the ladder" if x is negative skew ( etc, x^2 ,x^3...). The book "An R and S-PLUS Companion To Applied Regression" has a section to deal with the data transformation.Especiall P109 is about transformation for normality and symmetry. Hope this helps. 2006/4/10, Jian Zhang <[EMAIL PROTECTED]>: > I think it is simply, but I cannot find the method to figure out "skewness". > Thanks! > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] CLI Issue
Maybe clt.examp() in TeachingDemos is what you want. 2006/4/8, A Mani <[EMAIL PROTECTED]>: > Hello, > I have a script that must be executed by R at the CLI completely > ... without halting execution on encountering an error (object not found). > Rcmdr works fine, but source behaves strangely in R-2.1... > > Thanks, > > -- > A. Mani > Member, Cal. Math. Soc > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Financial functions
I don't know what PMT, etc, does. So I just give some hints and maybe it is not so useful. There are several packages in CRAN related to financial.Have you try to find some functions in them? fBasics Rmetrics - Marketes and Basic Statistics fCalendar Rmetrics - Chronological Objects fExtremes Rmetrics - Extreme Financial Market Data fMultivar Rmetrics - Multivariate Market Analysis fOptions Rmetrics - Option Valuation fPortfolio Rmetrics - Portfolio Selection and Optimization fSeries Rmetrics - The Dynamical Process Behind Markets 2006/4/5, vittorio <[EMAIL PROTECTED]>: > In what R package(-s) can I find the entire set of financial functions that > you can find in MS-Excel such as PMT, PPMT, FV and IPMT? > > Ciao > Vittorio > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] -newbie | RODBC import query
I just try and it works well for dbase III and dBase IV format database,but if the database is dBase II format,some error comes.I hope this help. > library(RODBC) > import_dat <- odbcConnectDbase(file.choose()) > (table_list <- sqlTables(import_dat)) TABLE_CAT TABLE_SCHEM TABLE_NAME TABLE_TYPE REMARKS 1 C:/tempnew TABLE > tester <- sqlFetch(import_dat,"new") > tester CASE LOC F_SIZE 1 3 1 3 2 8 1 4 3 9 1 2 4 10 1 3 5 11 1 3 > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major2 minor2.1 year 2005 month12 day 20 svn rev 36812 language R 2006/4/2, Evan Cooch <[EMAIL PROTECTED]>: > Greetings - > > After 20+ years of using SAS, for a variety of reasons, I'm using [R] > for a bunch of things - while I'm getting a pretty good a handling > [R] for script programming, and statistical analysis, I'm struggling > with 'pulling data into [R]'. For reasons beyond my control, a number > of the files I get sent to 'work with' are in Dbase format (*.dbf). > For another host of reasons, I need to be able to read directly into > [R] from these files (no using intermediate .CVS or delimited ASCII files). > > OK, so after a bit of reading, seems I need to use RODBC (I'm using > [R] 2.2.1 for Windows, at the moment). But, I can't seem to figure > out the basics. Suppose the file I need to 'work with' is > test.dbf So, I try the following: > > library(RODBC); > import_dat <- odbcConnectDbase("c:\documents and > settings\egc\desktop\test.dbf") > > OK, so far so good - well, at least no outright errors gets chunked > out to the console. Now what? Here's where I get stuck. There is a > table in the test.dbf file called TEST. But, the following > > tester <- sqlFetch(import_dat,"TEST") > > blows up - I get the following error message in the console: > > Error in odbcTableExists(import_dat, sqtable) : > 'TEST': table not found on channel > > OK - so it doesn't seem to find the table TEST in test.dbf. I tried > lower-case for TEST (i.e., test), but that doesn't seem to solve the > problem. OK, so lets pretend I don't know what the table in test.dbf > is called, and use sqlTables instead: > > table_list <- sqlTables(import_dat) > > When I then enter table_list in the console, I get > > [1] TABLE_CAT TABLE_SCHEM TABLE_NAME TABLE_TYPE REMARKS > <0 rows> (or 0-length row.names) > > Meaning, what? It almost seems that its telling me there is nothing > in test.dbf. Well, there definitely is (I can open it up in Excel - > shudder), but, perhaps it is unable to recognize whats there. > > > Suggestions? Apologies if this is easy, or (worse) and FAQ. > > Thanks! > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] New R user looking from help
Why not just post your question directly? If someone(including me,of course!) know the solution to your question,they will help you. 2006/4/3, Brian Quinif <[EMAIL PROTECTED]>: > Dear R users, > > I am trying to become a convert to R (from Stata), and I'm having some > growing pains. Is there anyone would be willing to answer a few basic > questions I have? Of course I am using the relevant help guides... > > Thanks, > > Brian Quinif > > ps. If there is anyone at UGA on this list, I'd love to hear from someone > local. > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] u value
> qnorm(1-0.05/2) [1] 1.959964 > qnorm(0.05/2,lower=F) [1] 1.959964 2006/3/31, XinMeng <[EMAIL PROTECTED]>: > As to the standard normal sidtribution,if alpha=0.05(2 tailed),how can I get > the "u value" by using R command? > > p.s result: u value is 1.96. > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] why these expressions cann't be nested?
> x<-matrix(1:10,5) > x=t(x) > colnames(x) <- letters[1:5] > x a b c d e [1,] 1 2 3 4 5 [2,] 6 7 8 9 10 If I try to nest the above expressions,II get the error. I know there is something wrong with it(and I won't write command like that now),but I don't why.So anyone can explain it for me? Thank you! > x<-matrix(1:10,5) > colnames(t(x)) <- letters[1:5] Error: couldn't find function "t<-" -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] data management on R
> cbind(a[,1,drop=F],b[,1,drop=F]) x n 1 1 1 2 2 2 2006/3/24, linda.s <[EMAIL PROTECTED]>: > On 3/23/06, Jim Porzak <[EMAIL PROTECTED]> wrote: > > C <- cbind(A[, 1], B[, 2]) > > > > > The result is: > [,1] [,2] > [1,]12 > [2,]38 > How to keep x and n as the column title? > Linda > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] handling warning messages
see ?options 'warn': sets the handling of warning messages. If 'warn' is negative all warnings are ignored. If 'warn' is zero (the default) warnings are stored until the top-level function returns. If fewer than 10 warnings were signalled they will be printed otherwise a message saying how many (max 50) were signalled. A top-level variable called 'last.warning' is created and can be viewed through the function 'warnings'. If 'warn' is one, warnings are printed as they occur. If 'warn' is two or larger all warnings are turned into errors. 'warning.expression': an R code expression to be called if a warning is generated, replacing the standard message. If non-null it is called irrespective of the value of option 'warn'. 'warnings.length': sets the truncation limit for error and warning messages. A non-negative integer, with allowed values 100...8192, default 1000. 2006/3/16, Sigal Blay <[EMAIL PROTECTED]>: > Is there any way to store the value of warnings but avoid printing them? > > A simplified example: > > out <- c(0.2,0.3,0.4) > > var <- c(2,3,4) > > outcome <- glm(out ~ var, family=binomial()) > Warning message: > non-integer #successes in a binomial glm! in: eval(expr, envir, enclos) > > I don't like the warning printed, > but I would like to be able to check it's value after the top-level function > has completed and than decide weather to print it or not. > > Thanks, > > Sigal Blay > Statistical Genetics Working Group > Department of Statistics and Actuarial Science > Simon Fraser University > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] tapply with unequal length of arguments
2006/3/12, Stefanie von Felten, IPW&IfU <[EMAIL PROTECTED]>: > Hi everyone, > > Is it possible to use tapply(x,y,mean) if not all groups of x by y are > of the same length (for example if you have one missing observation)? Yes,It works. > I tried tapply(x,y,mean,na.omit=T) but it doesn't work! What does "it doesn't work" mean exactly?Can you give an example and the error msg? > Steffi > -- > - > Stefanie von Felten > Doktorandin > > ETH Zürich > Institut für Pflanzenwissenschaften > ETH Zentrum, LFW A 2 > > Telefon: 044 632 85 97 > Telefax: 044 632 11 53 > e-mail: [EMAIL PROTECTED] > http://www.ipw.agrl.ethz.ch/~svfelten/ > > und: > > Universität Zürich > Institut für Umweltwissenschaften > Winterthurerstrasse 190 > 8057 Zürich > > Telefon: 044 635 61 23 > Telefax: 044 635 57 11 > e-mail: [EMAIL PROTECTED] > http://www.unizh.ch/uwinst/homepages/steffi.html > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] import from LISREL output of parameter estimates
The ouput from LISREL is a matrix,so the read.matrix(tseries) will do the job in this situation. ?read.matrix read.matrix(tseries) R Documentation Read Matrix Data Description Reads a matrix data file. Usage read.matrix(file, header = FALSE, sep = "", skip = 0) 2006/3/10, Felix Flory <[EMAIL PROTECTED]>: > I am using R and LISREL for simulation studies. R generates the data > that is analyzed with LISREL. > In LISREL I use "PV" in the LISREL output statement to request estimated > variances. LISREL writes these in a file that looks like this: > > 1 0 0 > 0.100331D+01 0.144845D+01 0.141009D+01 0.214423D+01 0.214129D+01 > 0.194464D+01 > 0.191531D+01 0.198328D+01 0.100683D+00-0.236392D-01 0.200655D+01 > 0.100142D+01 > 0.572501D+01 0.131652D+01 0.112175D+01 0.186140D+01 0.212321D+01 > 0.207455D+01 > 0.201915D+01-0.224004D+01 0.966613D+00 0.459977D+01 0.133921D+01 > 0.613532D+01 > 0.201852D+01 0.198881D+01 0.203360D+01 0.200934D+01-0.115235D+01 > 0.975292D+00 > -0.756997D-01 0.341922D+01 0.334352D+01 0.360463D-01-0.112819D+00 > > I need a function that reads these numbers back into R. I tried around with > > read.fwf("pv.lpr", widths=rep(13, 6), skip=1) > read.fortran() > scan() > > without success. > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] 'less' for R?
As Prof Brian Ripley has pointed out,That changes the object if you make a change in the editor, so definitely NOT to be recommended. And you should use invisible(edit(dat.frame)) instead. 2006/3/9, Christos Hatzis <[EMAIL PROTECTED]>: > Or > fix(data.frame) > to open it in the spreadsheet-like data editor. > > -Christos Hatzis > > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Duncan Murdoch > Sent: Wednesday, March 08, 2006 12:26 PM > To: [EMAIL PROTECTED] > Cc: r-help > Subject: Re: [R] 'less' for R? > > On 3/8/2006 12:03 PM, Federico Calboli wrote: > > Hi All, > > > > is there an equivalent of the Unix command 'less' (or 'more'), so I > > can look at what's inside a data.frame or a matrix without having it > > printed out on console? > > > > I am using R on Debian Linux and Mac OS 10.4.5 > > I think you want page(). head() and tail() are also useful, as equivalents > to the head and tail commands. > > Duncan Murdoch > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Multiple logistic regression
Do you mean multinomial logistic model? If it is,the multinom function in nnet package and multinomial function in VGAM(http://www.stat.auckland.ac.nz/~yee) package can do it. But I have no idea about the c-index. 2006/3/8, Stephanie Delalieux <[EMAIL PROTECTED]>: > Dear R-users, > > Is there a function in R that classifies data in more than 2 groups using > logistic regression/classification? I want to compare the c-indices of > earlier research (lrm, binary response variables) with new c-indices > obtained from 'multiple' (more response variables) logistic regression. > > Best regards, > Stephanie Delalieux > > Department Biosystems > M³-BIORES > Group of Geomatics Engineering > [EMAIL PROTECTED] > > > Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] glm automation
I just pointed out the mistake about using index. Andy's post let me know the trouble of using formula like that.It's valuable information for me:) Thank you! 在 06-3-8,Liaw, Andy<[EMAIL PROTECTED]> 写道: > From: ronggui > > > > 2006/3/8, A Mani <[EMAIL PROTECTED]>: > > > Hello, > > > I have two problems in automating multiple glm(s) > > operations. > > > The data file is tab delimited file with headers and two > > columns. like > > > > > > "ABC" "EFG" > > > 1 2 > > > 2 3 > > > 3 4 > > > dat <- read.table("FILENAME", header=TRUE, sep="\t", > > na.strings="NA", > > > dec=".", strip.white=TRUE) dataf <- read.table("FILENAME", > > > header=FALSE, sep="\t", na.strings="NA", dec=".", strip.white=TRUE) > > > norm1 <- glm(dataf[1,1] ~ dataf[1,2], family= normal(log), data=dat) > > > norm2 <- glm(dataf[1,1] ~ dataf[1,2], family= > > normal(identity), data=dat) > > > and so on. > > It should be > > norm1 <- glm(dataf[,1] ~ dataf[,2], family= normal(log), > > data=dat) norm2 <- glm(dataf[,1] ~ dataf[,2], family= > > normal(identity), data=dat) > > > > you should read the document of "[" about how to use index. > > I wish people would just give up on (ab)using model formula like that. IMHO > it's really asking for trouble down the road. For example: > > > n <- 5 > > d1 <- data.frame(x=1:n, y=rnorm(n)) > > d2 <- data.frame(u=n:1, v=rnorm(n)) > > d3 <- data.frame(y=rnorm(n), x=n:1) > > f1 <- lm(d1[,2] ~ d1[,1], data=d1) > > f2 <- lm(y ~ x, data=d1) > > predict(f1) >12345 > -1.767697694 -1.326691900 -0.885686106 -0.444680312 -0.003674518 > > predict(f2) >12345 > -1.767697694 -1.326691900 -0.885686106 -0.444680312 -0.003674518 > > predict(f1, d2) >12345 > -1.767697694 -1.326691900 -0.885686106 -0.444680312 -0.003674518 > > Notice anything odd above? > > > predict(f2, d3) >12345 > -0.003674518 -0.444680312 -0.885686106 -1.326691900 -1.767697694 > > Now that's more like it... > > Andy > > > > > > But glm does not work on the data unless I write ABC and > > EFG there... > > > I want to automate the script for multiple files. > > > > > > The other problem is to write the plot(GLM) to a file without > > > displaying it at stdout. > > > > > > Thanks, > > > > > > > > > A. Mani > > > Member, Cal. Math. Soc > > > > > > [[alternative HTML version deleted]] > > > > > > __ > > > R-help@stat.math.ethz.ch mailing list > > > https://stat.ethz.ch/mailman/listinfo/r-help > > > PLEASE do read the posting guide! > > > http://www.R-project.org/posting-guide.html > > > > > > > > > -- > > 黄荣贵 > > Deparment of Sociology > > Fudan University > > > > > > > -- > Notice: This e-mail message, together with any attachment...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to do it without for loops?
Thank you for all . One more question.How can I calculate these efficiently? set.seed(100) dat<-data.frame(x1=rnorm(20),x2=rnorm(20),u=rnorm(20),id=round(2*runif(20))) # In this example,id's elements are 0,1,2. y<-list() for (i in 0:2){ X<-as.matrix(subset(dat,id==i,c("x1","x2"))) u<-as.matrix(subset(dat,id==i,c("u"))) y[[i+1]]<-t(X)%*%u%*%t(u)%*%X } y[[1]]+y[[2]]+y[[3]] the above code is not elegant.And my second solution to this problem is using by to get a list. matlis<-by(dat, dat$id, function(x){ a<-as.matrix(x[,c("x1","x2")]) b<-as.matrix(x[, "u"]) t(a) %*% b %*% t(b) %*% a }) S <- matrix(unlist(matlis), 4, length(matlis)) S1 <- matrix(rowSums(S), 2, 2) The code works ,but I want to ask if there is any other more better ways to do it? It seems that this kind of computation is quite common. 2006/2/28, Gabor Grothendieck <[EMAIL PROTECTED]>: > Try: > > crossprod(x) > > or > > t(x) %*% x > > On 2/28/06, ronggui <[EMAIL PROTECTED]> wrote: > > This is the code: > > > > x<-matrix(rnorm(20),5) > > y<-list() > > for (i in seq(nrow(x))) y[[i]]<-t(x[i,,drop=F])%*%x[i,,drop=F] > > y[[1]]+y[[2]]+y[[3]]+y[[4]]+y[[5]] > > > > How can I do it without using for loops? > > Thank you in advance! > > -- > > ronggui > > Deparment of Sociology > > Fudan University > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] glm automation
2006/3/8, A Mani <[EMAIL PROTECTED]>: > Hello, > I have two problems in automating multiple glm(s) operations. > The data file is tab delimited file with headers and two columns. like > > "ABC" "EFG" > 1 2 > 2 3 > 3 4 > dat <- read.table("FILENAME", header=TRUE, sep="\t", na.strings="NA", > dec=".", strip.white=TRUE) > dataf <- read.table("FILENAME", header=FALSE, sep="\t", na.strings="NA", > dec=".", strip.white=TRUE) > norm1 <- glm(dataf[1,1] ~ dataf[1,2], family= normal(log), data=dat) > norm2 <- glm(dataf[1,1] ~ dataf[1,2], family= normal(identity), data=dat) > and so on. It should be norm1 <- glm(dataf[,1] ~ dataf[,2], family= normal(log), data=dat) norm2 <- glm(dataf[,1] ~ dataf[,2], family= normal(identity), data=dat) you should read the document of "[" about how to use index. > But glm does not work on the data unless I write ABC and EFG there... I want > to automate the script for multiple files. > > The other problem is to write the plot(GLM) to a file without displaying it > at stdout. > > Thanks, > > > A. Mani > Member, Cal. Math. Soc > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Two quick questions
The second question: STATA: use auto collapse (sum) price mpg,by( make foreign) R: if you have the same data set named auto in R whatyouwant <- aggregate(auto[,c("mpg","price")],by=auto[,c("make","foreign")],FUN=sum) 2006/3/3, Serguei Kaniovski <[EMAIL PROTECTED]>: > Hi all, > > 1. How to construct a date from three variables year, month, and day, > where all three are integers? > > 2. I have a dataframe by date and sector. I would like to add-up all > entries for all variable with identical date and sector, replacing the > original entries, i.e. emulate the STATA command "collapse (sum) var1 > var2 var3, by(date sector)". > > Thank you, > Serguei Kaniovski > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Command-line editing & history
And JGR has that features as well. 2006/3/3, Liaw, Andy <[EMAIL PROTECTED]>: > Unless I'm mistaken, all those features (and more) are available if you run > R within ESS/(X)Emacs. > > Andy > > From: John McHenry > > > >Hi all, > > > > Are there any plans to add more functionality to command-line > > editing and history editing on the command line? > > > > In MATLAB (I know, comparisons are odious ...), you can type > > "p" and up-arrow on the command line and scroll through the > > recently entered commands beginning with "p". This is a very > > useful feature and something that I believe is not replicated in R. > > Please correct me if I'm wrong; currently I use history(Inf) > > in R, search for what I want and cut and paste if I find what > > I'm looking for. > > > > Also in MATLAB, tab completion is available for directory > > listings and also for function name completion. Again, I'm > > unaware of how to do this in R. The added MATLAB > > functionality makes finding files easy on the command line > > and it also saves the fingers on long function names. > > > > Thanks, > > > > Jack. > > > > > > - > > > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > > > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] How to do it without for loops?
This is the code: x<-matrix(rnorm(20),5) y<-list() for (i in seq(nrow(x))) y[[i]]<-t(x[i,,drop=F])%*%x[i,,drop=F] y[[1]]+y[[2]]+y[[3]]+y[[4]]+y[[5]] How can I do it without using for loops? Thank you in advance! -- ronggui Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] does multinomial logistic model from multinom (nnet) has logLik?
I should ues "Not obvious " instead of "invalid", this is my mistake. 2006/2/24, Prof Brian Ripley <[EMAIL PROTECTED]>: > Please note, I told you that the deviance was minus twice log-likelihood > unless summ > 0. I had not checked the latter case, where it is not > obvious, but I did not say it was invalid. > > In fact the answer is to be found on p.203 of MASS4 (we do ask people to > read the supporting documentation), and this is valid also for summ > 0. I did read the help page in nnet.And MASS4 is not avaivable just now :( I will check that when I can. > I will add a comment to the help file. appreciate! > On Wed, 22 Feb 2006, ronggui wrote: > > > Here is a function for calculating the measures of fit for > > multinomial logistic model (using nnet::multinom).If anything wrong ,I > > hope experts point it out.Thank you. > > > > fitstat <- function(object) { > > #thanks Ripley, B. D. for telling how to get the LogLik and when is not > > obvious. > > {if (!is.null(object$call$summ) && !identical(object$call$summ,0)) > > stop("when 'summ' argument is not zero,can NOT get Loglik") } > > object.base <- update(object,.~1,trace=FALSE) > > dev.base <- deviance(object.base) ; L.base <- - dev.base/2 > > dev.full <- deviance(object) ; L.full <- - dev.full/2 > > G2 <- dev.base - dev.full > > df <- object$edf - object.base$edf > > LR.test.p <- pchisq(G2,df,lower=F) > > > > aic <- object$AIC > > > > n<-dim(object$residuals)[1] > > > > #get the predict value to cal count R2 > > pre <- predict(object,type="class") > > y <- eval.parent(object$call$data)[,as.character(object$call$formula[[2]])] > > if (!identical(length(y),length(pre))) stop("Length not matched.") > > tab <- table(y,pre) > > if (!identical(dim(tab)[1],dim(tab)[2])) stop("pred and y have diff > > nlevels") > > ad <- max(rowSums(tab))#max of row sum > > > > #cal R2 > > ML.R2 <- 1-exp(-G2/n) > > McFadden.R2 <- 1-(L.full/L.base) > > McFadden.Adj.R2 <- 1-((L.full-mod$edf)/L.base) > > Cragg.Uhler.R2 <- ML.R2/(1-exp(2*L.base/n)) > > Count.R2 <- sum(diag(tab))/sum(tab) > > Count.adj.R2 <- (sum(diag(tab))-ad)/(sum(tab)-ad) > > > > #get the result > > res<-list(LR=G2,df=df,LR.test.p =LR.test.p > > ,aic=aic,ML.R2=ML.R2,Cragg.Uhler.R2=Cragg.Uhler.R2,McFadden.R2 > > =McFadden.R2 > > ,McFadden.Adj.R2=McFadden.Adj.R2,Count.R2=Count.R2,Count.adj.R2=Count.adj.R2) > > > > #print the result > > cat("\n", > >paste(rep("-",21)), > >"\n The Fitstats are : \n", > >sprintf("G2(%d) = %f",df,G2), > >" ,Prob ",format.pval(LR.test.p), > >"\n",sprintf("AIC = %f",aic), > >sprintf(",ML.R2 = %f \n",ML.R2), > >paste(rep("-",21)),"\n", > >sprintf("Cragg.Uhler.R2 = %f \n",Cragg.Uhler.R2), > >sprintf("McFadden.R2 = %f \n",McFadden.R2), > >sprintf("McFadden.Adj.R2 = %f \n",McFadden.Adj.R2), > >sprintf("Count.R2= %f \n",Count.R2), > >sprintf("Count.adj.R2= %f \n",Count.adj.R2), > >"\n Note:The maxinum of ML R2 is less than 1 \n", > >paste(rep("-",21)),"\n") > > invisible(res) > > } > > > > #example > > require(nnet) > > data(mexico,package="Zelig") > > mod <- multinom(vote88 ~ pristr + othcok + othsocok,mexico) > > summary(mod,cor=F) > > fitstat(mod) > > > > #reference: > > #J. SCOTT LONG and JEREMY FREESE,REGRESSION MODELS FOR CATEGORICAL > > DEPENDENT VARIABLES USING STATA. > > > >> fitstat(mod) > > > > - - - - - - - - - - - - - - - - - - - - - > > The Fitstats are : > > G2(6) = 381.351620 ,Prob < 2.22e-16 > > AIC = 2376.571142 ,ML.R2 = 0.244679 > > - - - - - - - - - - - - - - - - - - - - - > > Cragg.Uhler.R2 = 0.282204 > > McFadden.R2 = 0.139082 > > McFadden.Adj.R2 = 0.133247 > > Count.R2= 0.596026 > > Count.adj.R2= 0.123003 > > > > Note:The maxinum of ML R2 is less than 1 > > - - - - - - - - - - - - - - - - - - - - - > > > > 在 06-2-22,ronggui<[EMAIL PROTECTED]> 写道: > >> So it's valid to get logLik (deviance/-2) when the summ argument is unused? > >> > >> Thank you. > >> > >> 2006/2/22, Prof Brian Ripley <[EMAIL P
Re: [R] does multinomial logistic model from multinom (nnet) has logLik?
Here is a function for calculating the measures of fit for multinomial logistic model (using nnet::multinom).If anything wrong ,I hope experts point it out.Thank you. fitstat <- function(object) { #thanks Ripley, B. D. for telling how to get the LogLik and when is invalid. {if (!is.null(object$call$summ) && !identical(object$call$summ,0)) stop("when 'summ' argument is not zero,can NOT get Loglik") } object.base <- update(object,.~1,trace=FALSE) dev.base <- deviance(object.base) ; L.base <- - dev.base/2 dev.full <- deviance(object) ; L.full <- - dev.full/2 G2 <- dev.base - dev.full df <- object$edf - object.base$edf LR.test.p <- pchisq(G2,df,lower=F) aic <- object$AIC n<-dim(object$residuals)[1] #get the predict value to cal count R2 pre <- predict(object,type="class") y <- eval.parent(object$call$data)[,as.character(object$call$formula[[2]])] if (!identical(length(y),length(pre))) stop("Length not matched.") tab <- table(y,pre) if (!identical(dim(tab)[1],dim(tab)[2])) stop("pred and y have diff nlevels") ad <- max(rowSums(tab))#max of row sum #cal R2 ML.R2 <- 1-exp(-G2/n) McFadden.R2 <- 1-(L.full/L.base) McFadden.Adj.R2 <- 1-((L.full-mod$edf)/L.base) Cragg.Uhler.R2 <- ML.R2/(1-exp(2*L.base/n)) Count.R2 <- sum(diag(tab))/sum(tab) Count.adj.R2 <- (sum(diag(tab))-ad)/(sum(tab)-ad) #get the result res<-list(LR=G2,df=df,LR.test.p =LR.test.p ,aic=aic,ML.R2=ML.R2,Cragg.Uhler.R2=Cragg.Uhler.R2,McFadden.R2 =McFadden.R2 ,McFadden.Adj.R2=McFadden.Adj.R2,Count.R2=Count.R2,Count.adj.R2=Count.adj.R2) #print the result cat("\n", paste(rep("-",21)), "\n The Fitstats are : \n", sprintf("G2(%d) = %f",df,G2), " ,Prob ",format.pval(LR.test.p), "\n",sprintf("AIC = %f",aic), sprintf(",ML.R2 = %f \n",ML.R2), paste(rep("-",21)),"\n", sprintf("Cragg.Uhler.R2 = %f \n",Cragg.Uhler.R2), sprintf("McFadden.R2 = %f \n",McFadden.R2), sprintf("McFadden.Adj.R2 = %f \n",McFadden.Adj.R2), sprintf("Count.R2= %f \n",Count.R2), sprintf("Count.adj.R2= %f \n",Count.adj.R2), "\n Note:The maxinum of ML R2 is less than 1 \n", paste(rep("-",21)),"\n") invisible(res) } #example require(nnet) data(mexico,package="Zelig") mod <- multinom(vote88 ~ pristr + othcok + othsocok,mexico) summary(mod,cor=F) fitstat(mod) #reference: #J. SCOTT LONG and JEREMY FREESE,REGRESSION MODELS FOR CATEGORICAL DEPENDENT VARIABLES USING STATA. > fitstat(mod) - - - - - - - - - - - - - - - - - - - - - The Fitstats are : G2(6) = 381.351620 ,Prob < 2.22e-16 AIC = 2376.571142 ,ML.R2 = 0.244679 - - - - - - - - - - - - - - - - - - - - - Cragg.Uhler.R2 = 0.282204 McFadden.R2 = 0.139082 McFadden.Adj.R2 = 0.133247 Count.R2= 0.596026 Count.adj.R2= 0.123003 Note:The maxinum of ML R2 is less than 1 - - - - - - - - - - - - - - - - - - - - - 在 06-2-22,ronggui<[EMAIL PROTECTED]> 写道: > So it's valid to get logLik (deviance/-2) when the summ argument is unused? > > Thank you. > > 2006/2/22, Prof Brian Ripley <[EMAIL PROTECTED]>: > > On Wed, 22 Feb 2006, ronggui wrote: > > > > > I want to get the logLik to calculate McFadden.R2 ,ML.R2 and > > > Cragg.Uhler.R2, but the value from multinom does not have logLik.So my > > > quetion is : is logLik meaningful to multinomial logistic model from > > > multinom?If it does, how can I get it? > > > > From the help page: > > > > Value: > > > > A 'nnet' object with additional components: > > > > deviance: the residual deviance. > > > > So it has a residual deviance. That is -2 log Lik in many cases (but not > > if the argument 'summ' is used) > > > > > Thank you! > > > > > > ps: I konw VGAM has function to get the multinomial logistic model > > > with logLik, but I prefer use the function from "official" R > > > packages . > > > > > > -- > > > ronggui > > > Deparment of Sociology > > > Fudan University > > > > -- > > Brian D. Ripley, [EMAIL PROTECTED] > > 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 > > > > > -- > 黄荣贵 > Deparment of Sociology > Fudan University > -- ronggui Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] does multinomial logistic model from multinom (nnet) has logLik?
So it's valid to get logLik (deviance/-2) when the summ argument is unused? Thank you. 2006/2/22, Prof Brian Ripley <[EMAIL PROTECTED]>: > On Wed, 22 Feb 2006, ronggui wrote: > > > I want to get the logLik to calculate McFadden.R2 ,ML.R2 and > > Cragg.Uhler.R2, but the value from multinom does not have logLik.So my > > quetion is : is logLik meaningful to multinomial logistic model from > > multinom?If it does, how can I get it? > > From the help page: > > Value: > > A 'nnet' object with additional components: > > deviance: the residual deviance. > > So it has a residual deviance. That is -2 log Lik in many cases (but not > if the argument 'summ' is used) > > > Thank you! > > > > ps: I konw VGAM has function to get the multinomial logistic model > > with logLik, but I prefer use the function from "official" R > > packages . > > > > -- > > ronggui > > Deparment of Sociology > > Fudan University > > -- > Brian D. Ripley, [EMAIL PROTECTED] > 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 > -- 黄荣贵 Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] does multinomial logistic model from multinom (nnet) has logLik?
I want to get the logLik to calculate McFadden.R2 ,ML.R2 and Cragg.Uhler.R2, but the value from multinom does not have logLik.So my quetion is : is logLik meaningful to multinomial logistic model from multinom?If it does, how can I get it? Thank you! ps: I konw VGAM has function to get the multinomial logistic model with logLik, but I prefer use the function from "official" R packages . -- ronggui Deparment of Sociology Fudan University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html