Re: [R] how to obtain par(ask=TRUE) with trellis-plots
Deepayan Sarkar [EMAIL PROTECTED] writes: On 1/11/06, Leo Gürtler [EMAIL PROTECTED] wrote: Dear alltogether, how can a delay like possible with par(ask=TRUE) be attained while using trellis-plots within a loop or something like that? the following draws each plot without waiting for a signal (mouse-klick), so par() does not work for that: library(nlme) for(i in 1:3) { fitlme - lme(Orthodont) par(ask=TRUE) # does not work with trellis print( plot(augPred(fitlme)) ) } See ?grid.prompt in the grid package. To use it you can either attach grid, or do grid::grid.prompt(TRUE) I happened to need this today (some example() sections are a bit unhelpful without it) and the only way I figured it out was by recalling this recent thread. Any chance of putting a suitable pointer in the help pages for trellis.par.set and/or trellis.device? -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ 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] Syntax for linear mixed model
N.W.Galwey nw.galwey at ukonline.co.uk writes: The syntax below works, and gives the expected results, in R version 2.0.0, provided that I have loaded packages Matrix, latticeExtra and lme4. However, I cannot get it to work in version 2.2.1. Can anyone tell me how to fit this model in the more recent version? barleyprogeny.model1lme - lme(yield_g_m2 ~ 1, data = barleyprogeny.unbalanced, random = ~ 1|fline + fblock) You must use the new style and call lmer when using package lme4 now. There is no full documentation on lmer yet since package lme4 is work in progress, but there are a few examples in the MEMSS package. However, I would suggest that for the rather simple model, you better don't load lme4 and Matrix, and use well-documented package nlme instead. Dieter __ 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] Different length of objects
Hello, i got an warning message in the following code: f-1:100 t-1:100 b-100 ll2 - function(b,f,t) { t-cumsum(t) tn-t[length(t)] i-seq(along=f) s1-(tn*exp(-b*tn)*sum(f[i]))/(1-exp(-b*tn)) s2-sum((f[i]*(t[i]*exp(-b*t[i])-t[i-1]*exp(b*t[i-1])))/(exp(-b*t[i-1])-exp(-b*t[i]))) s1-s2 } ll2(b,f,t) i think, the problem here is, that t[0] doesn't exist and so i got different length of objects. want can i do to avoid this error? the assumption is that t[0] should be 0. best regards andreas __ 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] Different length of objects
ok, thank you, in my problem i want to solve the following equation numericaly for b , t_n indicates the last value of t (t_n*exp(-b*t_n)*sum_{i=1}^{n} f_i) / (1-exp(-b*t_n)) - (sum_{i=1}^{n} (f_i*(t_i*exp(-b*t_i)-t_{i-1}*exp(-b*t_{i-1}))) / (exp(-b*t_{i-1})-exp(-b*t_i)) ) = 0 b is then the mle. jim holtman wrote: If you type t[0] you will get the value numeric(0) Which is a numeric vector of lenght 0; this is not the same a the value of 0. t[0] does not select any value. If you expect this to happen in your code, then check against it and assign whatever value you want: ifelse(length(t[i]) == 0, 0, t[i]) On 1/14/06, [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Hello, i got an warning message in the following code: f-1:100 t-1:100 b-100 ll2 - function(b,f,t) { t-cumsum(t) tn-t[length(t)] i-seq(along=f) s1-(tn*exp(-b*tn)*sum(f[i]))/(1-exp(-b*tn)) s2-sum((f[i]*(t[i]*exp(-b*t[i])-t[i-1]*exp(b*t[i-1])))/(exp(-b*t[i-1])-exp(-b*t[i]))) s1-s2 } ll2(b,f,t) i think, the problem here is, that t[0] doesn't exist and so i got different length of objects. want can i do to avoid this error? the assumption is that t[0] should be 0. best regards andreas __ R-help@stat.math.ethz.ch mailto: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 -- Jim Holtman Cincinnati, OH +1 513 247 0281 What the problem you are trying to solve? __ 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] LaTeX slide show (Was: Re: Taking code from packages)
On 1/14/2006 2:39 AM, Henrik Bengtsson wrote: Duncan Murdoch wrote: On 1/13/2006 2:04 AM, Ales Ziberna wrote: Hello! [snip] (I'm a little sensitive about dependencies now, since the LaTeX seminar template I've used a few times no longer works. It depends on too many LaTeX packages, and someone, somewhere has introduced incompatibilities in them. Seems like I'll be forced to use Powerpoint or Impress.) Try LaTeX Beamer! It is the best thing that happend to LaTeX in a long time. Simply beautiful, intuitive and very easy to use, and it's not yet another 'seminar' or 'prosper'. Part of MikTeX now. See http://latex-beamer.sourceforge.net/ for documentation, examples etc. Thanks to Henrik and Stephen Eglen for this suggestion. It does look nice (though the test presentation, beamerexample1.tex failed with ! Undefined control sequence. recently read \rowcolors l.937 \end{frame} indicating some version incompatibility with what I've got installed, the simpler examples all seem to work and do indeed give nice output.) 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] lmer and handling heteroscedasticity
Dear altogether, is it possible to integrate weights arguments within lmer to incorporate statements to handle heteroscedasticity as it is possible with lme? I searched the R-archive but found nothing, insofer I assume it is not possible, but as lmer is under heavy develpoment, maybe something changed or is solved differently. Thus my question: While encountering heavy heteroscedasticity within data, lmer is not the right application to use, but use instead lme? Thanks in advance for a short statement, best , leo -- email: [EMAIL PROTECTED] www: http://www.anicca-vijja.de/ __ 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] (no subject)
I am having difficulty installing the package lattice. First I tried downloading it from the CRAN site (in the normal way) : the message said it worked but when I typed library I got an error message (there is no package). Second I tried installing it from the local zip. I have reproduced the result below. utils:::menuInstallLocal() package 'lattice' successfully unpacked and MD5 sums checked Warning: cannot remove prior installation of package 'lattice' updating HTML package descriptions library(lattice) Error in library(lattice) : there is no package called 'lattice' Have I missed something? Apologies if it is something really obvious. Michael Anyadike-Danes Economic Research Institute of Northern Ireland Floral Buildings 2-14 East Bridge Street Belfast BT1 3NQ Tel: (028) 90727362 Fax: (028) 90319003 [[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
Re: [R] LaTeX slide show (Was: Re: Taking code from packages)
Duncan, it seems that you did not update 'xcolor' package properly. That's where \rowcolors is defined. In some instances, especially under MikTeX, the automatic update fails to update xcolor.sty. So, I suggest you download the latest xcolor package from the same place as the beamer package and then manually run 'latex xcolor.ins' to regenerate xcolor.sty. Then move the *.def and *.sty file to the proper places to gain full compatibility. Janusz. ** Janusz Kawczak ** ** UNC at Charlotte, Department of Mathematics Statistics, Room 345B ** ** 9201 University City Blvd** ** Charlotte, NC, 28223-0001, U.S.A.** ** Tel.: (W) (704) 687-2566 Fax.: (704) 687-6415 ** All truth passes through three stages. First, it is ridiculed, second it is violently opposed, and third, it is accepted as self-evident. -- Arthur Schopenhauer On Sat, 14 Jan 2006, Duncan Murdoch wrote: On 1/14/2006 2:39 AM, Henrik Bengtsson wrote: Duncan Murdoch wrote: On 1/13/2006 2:04 AM, Ales Ziberna wrote: Hello! [snip] (I'm a little sensitive about dependencies now, since the LaTeX seminar template I've used a few times no longer works. It depends on too many LaTeX packages, and someone, somewhere has introduced incompatibilities in them. Seems like I'll be forced to use Powerpoint or Impress.) Try LaTeX Beamer! It is the best thing that happend to LaTeX in a long time. Simply beautiful, intuitive and very easy to use, and it's not yet another 'seminar' or 'prosper'. Part of MikTeX now. See http://latex-beamer.sourceforge.net/ for documentation, examples etc. Thanks to Henrik and Stephen Eglen for this suggestion. It does look nice (though the test presentation, beamerexample1.tex failed with ! Undefined control sequence. recently read \rowcolors l.937 \end{frame} indicating some version incompatibility with what I've got installed, the simpler examples all seem to work and do indeed give nice output.) 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
Re: [R] problems installing lattice on Windows; was: (no subject)
Michael Anyadike-Danes wrote: I am having difficulty installing the package lattice. First I tried downloading it from the CRAN site (in the normal way) : the message said it worked but when I typed library I got an error message (there is no package). lattice is shipped with R. You don't need to install it separately unless you want a more recent version in which case you simply can use update.packages(). Second I tried installing it from the local zip. I have reproduced the result below. utils:::menuInstallLocal() package 'lattice' successfully unpacked and MD5 sums checked Warning: cannot remove prior installation of package 'lattice' So you had lattice loaded once you decided to update. This does not work under Windows as you have certainly already read in the R for Windows FAQs. Start R without loading lattice and then update the package. updating HTML package descriptions library(lattice) Error in library(lattice) : there is no package called 'lattice' Have I missed something? Yes: reading the manuals and the posting guide (which also asks you to use a sensible subject line). I assume this is R under Windows, and I hope a recent copy such as R-2.2.1. Uwe Ligges Apologies if it is something really obvious. Michael Anyadike-Danes Economic Research Institute of Northern Ireland Floral Buildings 2-14 East Bridge Street Belfast BT1 3NQ Tel: (028) 90727362 Fax: (028) 90319003 [[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
Re: [R] change lattice panel background color
On 1/13/06, Waichler, Scott R [EMAIL PROTECTED] wrote: I can't find a way to change just the panel background color in lattice. I would like NA regions in levelplot() to appear black. I've tried the trellis.par.set() stuff, but it it makes the background of the whole graphic black. Use panel.fill in a panel function, e.g. (untested) panel = function(...) { panel.fill(col = black) panel.levelplot(...) } -Deepayan __ 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] R newbie example code question
Ted.Harding at nessie.mcc.ac.uk writes: [...] The solution I finally opted for, and still use, is based (in a Linux environment) on including the following code in your .Rprofile file: .xthelp - function() { tdir - tempdir() pgr - paste(tdir, /pgr, sep=) con - file(pgr, w) cat(#! /bin/bash\n, file=con) cat(export HLPFIL=`mktemp , tdir, /R_hlp.XX`\n, sep=, file=con) cat(cat $HLPFIL\nxterm -e less $HLPFIL \n, file=con) close(con) system(paste(chmod 755 , pgr, sep=)) options(pager=pgr) } .xthelp() rm(.xthelp) (and it's also specific to the 'bash' shell because of the #! /bin/bash\n, but you should be able to change this appropriately). The above was posted by Roger Bivand on 27 May. [...] I also like the function, it's beautiful. I wonder if anyone could help me with the correct syntax for my bash shell (I assume this is the problem) because I get this error: Error in rm(.xthelp) : cannot remove variables from base namespace when starting R and when installing a new package. Thank you, Adrian __ 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] R newbie example code question
On Friday 13 January 2006 17:45, Ted Harding wrote: On 13-Jan-06 Michael Friendly wrote: Ted: Your .xthelp is extremely useful, help on Linux being otherwise quite awkward to use since a pager in the same window make it hard to cut/paste examples --- where 'more' or 'less' really means 'instead of' :-) Glad you found it useful. I find it indispensable! For the record: this is not my code but Roger Bivand's, it being the one out of several suggestions on that thread which I decided to adopt. I still admire the neat way he wrapped it all up. [...snip...] I also like the function very much, but I get an annoying error when starting R or when installing a new package: Error in rm(.xthelp) : cannot remove variables from base namespace I assume it has something to do with my bash shell, but I have no idea what to do. I run I inside Kubuntu 5.10 Breezy (compiled from source). R.Version() $platform [1] i686-pc-linux-gnu $arch [1] i686 $os [1] linux-gnu $system [1] i686, linux-gnu $status [1] $major [1] 2 $minor [1] 2.1 $year [1] 2005 $month [1] 12 $day [1] 20 $svn rev [1] 36812 $language [1] R Thank you, Adrian -- Adrian DUSA Romanian Social Data Archive 1, Schitu Magureanu Bd 050025 Bucharest sector 5 Romania Tel./Fax: +40 21 3126618 \ +40 21 3120210 / int.101 __ 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] better way to replace missing values with zero
I hope this helps: foo - data.frame(x=1:3,y=letters[1:3],z=4:6, w=as.Date(c(02/27/92, 02/27/92, 01/14/92), %m/%d/%y)) foo[2,] - NA foo xy z w 1 1a 4 1992-02-27 2 NA NA NA NA 3 3c 6 1992-01-14 class(foo$w) [1] Date mode(foo$w) [1] numeric a - sapply(foo, is.numeric) b - !sapply(foo, class)==Date foo[!complete.cases(foo),a b] - 0 foo xy z w 1 1a 4 1992-02-27 2 0 NA 0 NA 3 3c 6 1992-01-14 cheers, Marco roger bos [EMAIL PROTECTED] wrote: I would like to replace all missing values (NAs) with zero like below--where ever they may be--but some of the column classes are non-numeric so I get an error: dim(temp) [1] 699 313 temp[is.na(temp)] - 0 Error in as.Date.default(value) : do not know how to convert 'value' to class Date So I have to use more conveluted code: for (k in c(1:ncol(temp))) { if (class(temp[, k])==numeric) { temp[, k][is.na(temp[, k])] - 0 } } This is much more code and requires a for loop. Can anyone please show me a better way? Thanks, Roger [[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 - Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever. [[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] Data Mining Course
Short course: Statistical Learning and Data Mining II: tools for tall and wide data Trevor Hastie and Robert Tibshirani, Stanford University Sheraton Hotel, Palo Alto, California, April 3-4, 2006. This two-day course gives a detailed overview of statistical models for data mining, inference and prediction. With the rapid developments in internet technology, genomics, financial risk modeling, and other high-tech industries, we rely increasingly more on data analysis and statistical models to exploit the vast amounts of data at our fingertips. This course is the third in a series, and follows our popular past offerings Modern Regression and Classification, and Statistical Learning and Data Mining. The two earlier courses are not a prerequisite for this new course. In this course we emphasize the tools useful for tackling modern-day data analysis problems. We focus on both tall data ( Np where N=#cases, p=#features) and wide data (pN). The tools include gradient boosting, SVMs and kernel methods, random forests, lasso and LARS, ridge regression and GAMs, supervised principal components, and cross-validation. We also present some interesting case studies in a variety of application areas. All our examples are developed using the S language, and most of the procedures we discuss are implemented in publicly available R packages. Please visit the site http://www-stat.stanford.edu/~hastie/sldm.html for more information and registration details. --- Trevor Hastie [EMAIL PROTECTED] Professor, Department of Statistics, Stanford University Phone: (650) 725-2231 (Statistics) Fax: (650) 725-8977 (650) 498-5233 (Biostatistics) Fax: (650) 725-6951 URL: http://www-stat.stanford.edu/~hastie address: room 104, Department of Statistics, Sequoia Hall 390 Serra Mall, Stanford University, CA 94305-4065 [[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
Re: [R] glmmPQL and variance structure
Thanks for providing a partially reproducible example. I believe the error message you cite came from lme. I say this, because I modified your call to glmmPQL2 to call lme and got the following: library(nlme) fit.lme - lme(y ~ trt + I(week 2), random = ~ 1 | ID, + data = bacteria, weights=varPower(~1)) Error in unlist(x, recursive, use.names) : argument not a list I consulted Pinheiro and Bates (2000) Mixed-Effects Models in S and S-Plus (Springer, sec. 5.2, p.211) to see that the syntax for varPower appears to be correct. I removed ~ and it worked, mostly: fit.lme - lme(y ~ trt + I(week 2), random = ~ 1 | ID, + data = bacteria, weights=varPower(1)) Warning message: - not meaningful for factors in: Ops.factor(y[revOrder], Fitted) I got an answer, though with a warning and not for the problem you want to solve. However, I then made this modification to a call to my own modification of Venables and Ripley's glmmPQL and it worked: fit. - glmmPQL.(y ~ trt + I(week 2), random = ~ 1 | ID, + family = binomial, data = bacteria, + weights.lme=varPower(1)) iteration 1 iteration 2 iteration 3 fit. Linear mixed-effects model fit by maximum likelihood Data: bacteria Log-likelihood: -541.0882 Fixed: y ~ trt + I(week 2) (Intercept) trtdrugtrtdrug+ I(week 2)TRUE 2.7742329 -1.0852566 -0.5896635 -1.2682626 Random effects: Formula: ~1 | ID (Intercept) Residual StdDev: 4.940885e-05 2.519018 Variance function: Structure: Power of variance covariate Formula: ~fitted(.) Parameter estimates: power 0.3926788 Number of Observations: 220 Number of Groups: 50 This function glmmPQL. adds an argument weights.lme to Venables and Ripley's glmmPQL and uses that in place of 'quote(varFixed(~invwt))' when provided; see below. hope this helps. spencer graves glmmPQL. - function (fixed, random, family, data, correlation, weights, weights.lme, control, niter = 10, verbose = TRUE, ...) { if (!require(nlme)) stop(package 'nlme' is essential) if (is.character(family)) family - get(family) if (is.function(family)) family - family() if (is.null(family$family)) { print(family) stop('family' not recognized) } m - mcall - Call - match.call() nm - names(m)[-1] wts.lme - mcall$weights.lme keep - is.element(nm, c(weights, data, subset, na.action)) for (i in nm[!keep]) m[[i]] - NULL allvars - if (is.list(random)) allvars - c(all.vars(fixed), names(random), unlist(lapply(random, function(x) all.vars(formula(x) else c(all.vars(fixed), all.vars(random)) Terms - if (missing(data)) terms(fixed) else terms(fixed, data = data) off - attr(Terms, offset) if (length(off - attr(Terms, offset))) allvars - c(allvars, as.character(attr(Terms, variables))[off + 1]) m$formula - as.formula(paste(~, paste(allvars, collapse = +))) environment(m$formula) - environment(fixed) m$drop.unused.levels - TRUE m[[1]] - as.name(model.frame) mf - eval.parent(m) off - model.offset(mf) if (is.null(off)) off - 0 w - model.weights(mf) if (is.null(w)) w - rep(1, nrow(mf)) mf$wts - w fit0 - glm(formula = fixed, family = family, data = mf, weights = wts, ...) w - fit0$prior.weights eta - fit0$linear.predictor zz - eta + fit0$residuals - off wz - fit0$weights fam - family nm - names(mcall)[-1] keep - is.element(nm, c(fixed, random, data, subset, na.action, control)) for (i in nm[!keep]) mcall[[i]] - NULL fixed[[2]] - quote(zz) mcall[[fixed]] - fixed mcall[[1]] - as.name(lme) mcall$random - random mcall$method - ML if (!missing(correlation)) mcall$correlation - correlation # weights.lme { if(is.null(wts.lme)) mcall$weights - quote(varFixed(~invwt)) else mcall$weights - wts.lme } mf$zz - zz mf$invwt - 1/wz mcall$data - mf for (i in 1:niter) { if (verbose) cat(iteration, i, \n) fit - eval(mcall) etaold - eta eta - fitted(fit) + off if (sum((eta - etaold)^2) 1e-06 * sum(eta^2)) break mu - fam$linkinv(eta) mu.eta.val - fam$mu.eta(eta) mf$zz - eta + (fit0$y - mu)/mu.eta.val - off wz - w * mu.eta.val^2/fam$variance(mu) mf$invwt - 1/wz mcall$data - mf } attributes(fit$logLik) - NULL fit$call - Call fit$family - family oldClass(fit) - c(glmmPQL, oldClass(fit)) fit } Patrick Giraudoux wrote: Dear listers, On the line of a last (unanswered) question about glmmPQL() of the library MASS, I am still wondering if it
Re: [R] how to obtain par(ask=TRUE) with trellis-plots
On 14 Jan 2006 11:17:18 +0100, Peter Dalgaard [EMAIL PROTECTED] wrote: Deepayan Sarkar [EMAIL PROTECTED] writes: [...] See ?grid.prompt in the grid package. To use it you can either attach grid, or do grid::grid.prompt(TRUE) I happened to need this today (some example() sections are a bit unhelpful without it) and the only way I figured it out was by recalling this recent thread. Any chance of putting a suitable pointer in the help pages for trellis.par.set and/or trellis.device? Will do. Deepayan __ 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] Can I call a R function from within C/C++ directly?
Dear all R users£¬ Can I call a R function from within C/C++ directly? I mean don't run R. Thank you! Regards, Shaozhong Zhao [EMAIL PROTECTED] 2006-01-13 __ 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 I ask for the C code inside an R function using .C? (Thanks)
Thanks all! Francisco provided the best solution for me, i.e., https://svn.r-project.org/R/trunk/ , where I can find what I want. Regards, Yingfu ### This message has been scanned by F-Secure Anti-Virus for Mic...{{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
[R] example(plot) question
From Windows RGui, I tried: example(plot) This worked as expected except that the various plots write over top of each other in the graphics window that is created. I then discovered that graphics history is not enabled during the example generation. I used the graphics window menu to enable the history and repeated example(plot), but this raises a couple of questions: Is there a command line equivalent for activating plot history? Is plot history a par() or options() setting or is it intrinsic to an individual graphics window? Is there an argument to example() that enables plot history and/or wouldn't it make sense to have this activated by default whenever an example() execution creates plots? I tried: help.search('plot record') help.search('plot history') help.search('history recording') without finding anything insightful to help with this topic, but I'm just betting more than one of you knows what I should have typed or where I should lookG. Thanks, Rob version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major2 minor2.0 year 2005 month10 day 06 svn rev 35749 language R [[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
Re: [R] Can I call a R function from within C/C++ directly?
On 1/14/2006 4:48 PM, Shaozhong Zhao wrote: Dear all R users£¬ Can I call a R function from within C/C++ directly? I mean don't run R. Thank you! Yes. See the R Extensions manual, in particular chapter 7, Linking GUIs and other front ends to R. 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
Re: [R] R-help Digest, Vol 35, Issue 14
Dear all, Is anybody aware of a tutorial, introduction, overview or alike for cluster analysis with R? I have been searching for something like that but it seems there are only a few rather specialized articles around. I would very much appreciate any hint. Thanks a million, Werner ___ Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de __ 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 unit root tests
Can anyone help with questions on correlations in lme? I provide below a self-contained toy example that I can't quite complete. QUESTIONS: 1. Is there a unit root test in R? Below please find a failed attempt to do this using lme. 2. Is there a corStruct class for first differences (unit root)? corAR1(1) generates an error. 3. How can store in another R object the estimated AR(1) coefficient from an lme object generated with 'lme(..., correlation=corAR1(form=~1|subj))'? 4. Why am I getting small p-values in testing for a unit root when I simulate an AR1(1)? TOY EXAMPLE nSubj - 4; nObs - 5; nSims - 2 UnitRootSims - array(NA, dim=c(nSims, 2), dimnames=list(NULL, c(AR1, p.value))) corAR1. - corAR1(form=~1|subj) corUnitRoot - corAR1(1, form=~1|subj, fixed=TRUE) # corAR1(1) not allowed. corUnitRoot - corAR1(0.9, form=~1|subj, fixed=TRUE) set.seed(123) library(nlme) for(i in 1:nSims){ e.subj - array(rnorm(nObs*nSubj), dim=c(nObs, nSubj), dimnames=list(paste(obs, 1:nObs, sep=), subj)) y.subj - apply(e.subj, 2, cumsum) Dat - data.frame(subj=rep(subj, each=nObs), y=as.vector(y.subj)) fitAR1 - lme(y~1, data=Dat, random=~1|subj, correlation=corAR1., method=ML) # UnitRootSims[i, 1] - ??? How to extract the AR1 estimate? fitUnitRoot - lme(y~1, data=Dat, random=~1|subj, correlation=corUnitRoot, method=ML) aovUnitRoot - anova(fitAR1, fitUnitRoot) UnitRootSims[i, 2] - aovUnitRoot[2, p-value] } UnitRootSims AR1 p.value [1,] NA 8.277712e-11 [2,] NA 1.174823e-08 # Why are the p-values so small? Shouldn't they be insignificant? Thanks, Spencer Graves If replies to this post will no longer be useful for you, then please discregard this comment. If not, I will start by saying that I could not understand enough of your question to respond directly. RSiteSearch(panel unit root) led me to an exchange we had following a related question you posted last October (ttp://finzi.psych.upenn.edu/R/Rhelp02a/archive/63545.html). Did you try the nlme package as suggested there? I've just now looked at that, and I confess I could not figure out how to do it in a few minutes. Do you want to perform a unit root test for a particular panel data set you have? Or do you want to develop software for a particular panel unit root test? If the former, I suggest you prepare a very simple toy example trying to do something like this using lme with perhaps corAR1, then send this list a question on whether it is possible to do what you want with lme, asking how to take the next step with the toy example. If rather you want to develop software for a particular unit root test, then I suggest you at least provide a more complete citation than just a la Arellano Bond. In either case, I also suggest you review the posting guide! www.R-project.org/posting-guide.html and try to make your post as easily understood as possible. In general, I think that posts that are clear and succinct tend to get quicker, more useful answers. Maybe I'm just dense, but I don't understand what you are asking. For example, your code includes print(levinlin(ws, year, id, lags = 3)). What is the levinlin function? RSiteSearch(levinlin) produced zero hits. hope this helps. spencer graves jukka ruohonen wrote: When finally got some time to do some coding, I started and stopped right after. The stationary test is a good starting point because it demonstrates how we should be able to move the very basic R matrices. I have a real- world small N data set with rows: id(n=1)---t1---variable1 ... id=(N=20)---T=21---variable1 Thus, a good test case. For first id I was considering something like this: lag - as.integer(lags) lags.p - lags + 1 id - unique(group) id.l - length(id) y.l - length(y) yid.l - length(y)/id.l if (lag yid.l -2) stop(\nlag too long for defined cross-sections.\n) #for (i in id) { lagy - y[2:yid.l] lagy.em - embed(lagy, lags) id.l - length(id) dy - diff(y)[1:yid.l-1] dy.em - embed(dy, lags) # } print(levinlin(ws, year, id, lags = 3)) Couldn't figure the loop over units out but with N = 1 the data transformation seemed to work just fine. Now we should pool the new variables within the panel and regress y over yt-1 and dy-t1 ++ dy-t-j with, say, BIC doing the job for d's (H0: y-1 ~ 0) for each in the panel. Now the above example puts the right-hand on columns, and if we are dealing with panel models in general, we should store the new variables together with dX's, which should then give clues to IV estimator with e.g. orthogonal deviations, e.g. k - y ~ yt-1 + x + as.factor(id)). So one confusing part is the requirement of some big storage base for different matrices doing the IV business with lags/levels - the amount of instruments can be enormous with possibly
Re: [R] glmmPQL and variance structure
I just identified an error in my recent post on this subject: There is a very good reason that Venables Ripley's glmmPQL did NOT include an argument like the weights.lme in the glmmPQL. included in my recent post: Their function calls glm first and then provides weights computed by glm to lme. If you want other weights, you need to consider appropriately the weights computed by glm. It may be reasonable to make your other weights proportional to the glm weights, but it would not be smart to do as I suggested a few hours ago, which ignored the glm weights. I hope this error doesn't seriously inconvenience you or anyone else who might read these comments. spencer graves Thanks for providing a partially reproducible example. I believe the error message you cite came from lme. I say this, because I modified your call to glmmPQL2 to call lme and got the following: library(nlme) fit.lme - lme(y ~ trt + I(week 2), random = ~ 1 | ID, + data = bacteria, weights=varPower(~1)) Error in unlist(x, recursive, use.names) : argument not a list I consulted Pinheiro and Bates (2000) Mixed-Effects Models in S and S-Plus (Springer, sec. 5.2, p.211) to see that the syntax for varPower appears to be correct. I removed ~ and it worked, mostly: fit.lme - lme(y ~ trt + I(week 2), random = ~ 1 | ID, + data = bacteria, weights=varPower(1)) Warning message: - not meaningful for factors in: Ops.factor(y[revOrder], Fitted) I got an answer, though with a warning and not for the problem you want to solve. However, I then made this modification to a call to my own modification of Venables and Ripley's glmmPQL and it worked: fit. - glmmPQL.(y ~ trt + I(week 2), random = ~ 1 | ID, + family = binomial, data = bacteria, + weights.lme=varPower(1)) iteration 1 iteration 2 iteration 3 fit. Linear mixed-effects model fit by maximum likelihood Data: bacteria Log-likelihood: -541.0882 Fixed: y ~ trt + I(week 2) (Intercept) trtdrugtrtdrug+ I(week 2)TRUE 2.7742329 -1.0852566 -0.5896635 -1.2682626 Random effects: Formula: ~1 | ID (Intercept) Residual StdDev: 4.940885e-05 2.519018 Variance function: Structure: Power of variance covariate Formula: ~fitted(.) Parameter estimates: power 0.3926788 Number of Observations: 220 Number of Groups: 50 This function glmmPQL. adds an argument weights.lme to Venables and Ripley's glmmPQL and uses that in place of 'quote(varFixed(~invwt))' when provided; see below. hope this helps. spencer graves glmmPQL. - function (fixed, random, family, data, correlation, weights, weights.lme, control, niter = 10, verbose = TRUE, ...) { if (!require(nlme)) stop(package 'nlme' is essential) if (is.character(family)) family - get(family) if (is.function(family)) family - family() if (is.null(family$family)) { print(family) stop('family' not recognized) } m - mcall - Call - match.call() nm - names(m)[-1] wts.lme - mcall$weights.lme keep - is.element(nm, c(weights, data, subset, na.action)) for (i in nm[!keep]) m[[i]] - NULL allvars - if (is.list(random)) allvars - c(all.vars(fixed), names(random), unlist(lapply(random, function(x) all.vars(formula(x) else c(all.vars(fixed), all.vars(random)) Terms - if (missing(data)) terms(fixed) else terms(fixed, data = data) off - attr(Terms, offset) if (length(off - attr(Terms, offset))) allvars - c(allvars, as.character(attr(Terms, variables))[off + 1]) m$formula - as.formula(paste(~, paste(allvars, collapse = +))) environment(m$formula) - environment(fixed) m$drop.unused.levels - TRUE m[[1]] - as.name(model.frame) mf - eval.parent(m) off - model.offset(mf) if (is.null(off)) off - 0 w - model.weights(mf) if (is.null(w)) w - rep(1, nrow(mf)) mf$wts - w fit0 - glm(formula = fixed, family = family, data = mf, weights = wts, ...) w - fit0$prior.weights eta - fit0$linear.predictor zz - eta + fit0$residuals - off wz - fit0$weights fam - family nm - names(mcall)[-1] keep - is.element(nm, c(fixed, random, data, subset, na.action, control)) for (i in nm[!keep]) mcall[[i]] - NULL fixed[[2]] - quote(zz) mcall[[fixed]] - fixed mcall[[1]] - as.name(lme) mcall$random - random mcall$method - ML if (!missing(correlation)) mcall$correlation - correlation # weights.lme { if(is.null(wts.lme)) mcall$weights - quote(varFixed(~invwt)) else mcall$weights - wts.lme } mf$zz - zz mf$invwt - 1/wz mcall$data - mf for (i in 1:niter)
Re: [R] R-help Digest, Vol 35, Issue 14
On Sun, 15 Jan 2006, Werner Wernersen wrote: Is anybody aware of a tutorial, introduction, overview or alike for cluster analysis with R? I have been searching for something like that but it seems there are only a few rather specialized articles around. Chapter 11 of MASS (the book discussed in the FAQ). -- 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
Re: [R] example(plot) question
You can either open a graphics device with history windows(record = TRUE) or open a graphics device and set par(ask=TRUE) to be asked for confirmation after each plot (as most demos do). Finally, if you always want graphics recorded on a windows() device, use options(graphics.record = TRUE) as documented in ?windows. (I am not sure how you would know about plot history without knowing that was the relevant device: e.g. both the rw-FAQ and the Windows README tell you.) On Sat, 14 Jan 2006, Robert W. Baer, Ph.D. wrote: From Windows RGui, I tried: example(plot) This worked as expected except that the various plots write over top of each other in the graphics window that is created. I then discovered that graphics history is not enabled during the example generation. I used the graphics window menu to enable the history and repeated example(plot), but this raises a couple of questions: Is there a command line equivalent for activating plot history? Is plot history a par() or options() setting or is it intrinsic to an individual graphics window? Is there an argument to example() that enables plot history and/or wouldn't it make sense to have this activated by default whenever an example() execution creates plots? I tried: help.search('plot record') help.search('plot history') help.search('history recording') without finding anything insightful to help with this topic, but I'm just betting more than one of you knows what I should have typed or where I should lookG. Thanks, Rob version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major2 minor2.0 year 2005 month10 day 06 svn rev 35749 language R [[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 -- 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