Re: [R] computer algebra in R
Just wanted to mention that the caracas package *may* be better at solving this problem Best Søren -Original Message- From: Konrad via R-help Reply-To: Konrad To: R-help@r-project.org Subject: [R] computer algebra in R Date: Tue, 28 Nov 2023 11:03:36 +0100 Dear all, I'm currently working on converting mathematica code (https://github.com/ASDSE/thermosimfit/blob/master/Packages/thermoHD-Comp/thermoCacheHD-1Comp.m) to R. The code is related to solve algebraic systems. > eqthermo = {h0 == h + hd + hga, d0 == d + hd, ga0 == ga + hga, kga == > hga / (h * ga), kd == hd / (h * d)}; > > (* IDA HD*) > sthdIDAcacheHD[fkd_, fkga_, fh0_, fd0_] := sthdIDAcacheHD[fkd, fkga, > fh0, fd0] = > Module[{eliHD, solvHD}, > eliHD = > Eliminate[ > eqthermo /. {d0 -> fd0, h0 -> fh0, kd -> fkd, kga -> > fkga}, {h, d, hga, ga}]; > solvHD = hd /. NSolve[eliHD, hd]; > Return[solvHD]; > ]; I tried to use the Ryacas package. However, I'm struggling with the Elimination step. Within this step a system of equations: 0.3==h+hd+hga,0.4==d+hd,ga0==ga+hga,0.2==hga/(ga h),0.1==hd/(d h) is transformed to: -12.+1040. hd+2575. hd^2-250. hd^3==ga0 hd (-200.+500. hd). My question is whether someone has experience with yacas and can tell me how to do this step in R. Beyond that, I would be grateful for every hint how to transfer this into R. All the best, Konrad __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Søren Højsgaard Head of Department of Mathematical Sciences Aalborg University, Denmark. Chair of the Danish Statistical Society __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R emulation of FindRoot in Mathematica
FCS1%2BqQvYdlvjyJMjzTOXhoS6AY%2FJQ%3D=0 PLEASE do read the posting guide <https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html=05%7C01%7Ctebert%40ufl.edu%7C7cb98cd926b34284cd5f08dafa28026c%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C638097347110882622%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C=m00vZP75nk9icL6H8Gc0dH1bHhkRCS9I5N27uORQmQ0%3D=0> https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html=05%7C01%7Ctebert%40ufl.edu%7C7cb98cd926b34284cd5f08dafa28026c%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C638097347110882622%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C=m00vZP75nk9icL6H8Gc0dH1bHhkRCS9I5N27uORQmQ0%3D=0 and provide commented, minimal, self-contained, reproducible code. __ <mailto:R-help@r-project.org> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see <https://stat.ethz.ch/mailman/listinfo/r-help> https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide <http://www.R-project.org/posting-guide.html> http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ <mailto:R-help@r-project.org> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see <https://stat.ethz.ch/mailman/listinfo/r-help> https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide <http://www.R-project.org/posting-guide.html> http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Søren Højsgaard Head of Department of Mathematical Sciences Aalborg University, Denmark [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Handling dependencies on Bioconductor packages for packages on CRAN
Dear all My gRbase package imports the packages from Bioconductor: graph, RBGL and Rgraphviz If these packages are not installed, then gRbase can not be installed. The error message is: ERROR: dependency ‘graph’ is not available for package ‘gRbase’ If I, prior to installation, run setRepositories and highlight 'BioC software', then gRbase installs as it should, because the graph package from Bioconductor is installed along with it. However, this extra step is an obstacle to many users of the package which means that either people do not use the package or people ask questions about this issue on stack overflow, R-help, by email to me etc. It is not a problem to get the package on CRAN because, I guess, the CRAN check machines already have the three bioconductor packages installed. Therefore, I wonder if there is a way of specifying, in the DESCRIPTION file or elsewhere, that these packages should be installed automatically from bioconductor. An alternative would be if one could force the error message ERROR: dependency ‘graph’ is not available for package ‘gRbase’ to be accompanied by a message about what the user then should do. Any good suggestions? Thanks in advance. Best regards Søren [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 the difference of AIC()
In the first model, I believe you estimate two parameters: the mean and the variance: > fm <- lm(y ~ 1) > 2*2 - 2 * logLik(fm) 'log Lik.' 40.49275 (df=2) > AIC(fm) [1] 40.49275 A zero mean model: fm0 <- lm(y ~ -1) > 2*1 - 2 * logLik(fm0) 'log Lik.' 39.00611 (df=1) > AIC(fm0) [1] 39.00611 Regards Søren On Wed, 2021-05-12 at 19:49 +0800, Jinsong Zhao wrote: > Hi there, > > I learned that AIC = 2 * npar - 2 * log(logLik(model)), where k is > the > number of estimated parameters in the model. > > For examle: > > set.seed(123) > > y <- rnorm(15) > > fm <- lm(y ~ 1) > In this example, npar should be 1, so, AIC is: > > 2*1 - 2 * logLik(fm) > 'log Lik.' 38.49275 (df=2) > > However, AIC() give: > > AIC(fm) > [1] 40.49275 > > I also try another AIC extract function: > > extractAIC(fm) > [1] 1.00 -4.075406 > > Since extractAIC() does not include the constant: n + n * log(2 * > pi), so: > > extractAIC(fm)[2] + 15 + 15 * log(2 * pi) > [1] 38.49275 > > It equals to the AIC calculated by 2*1 - 2 * logLik(fm), but > different > with the return of AIC(). > > It seems that AIC use 2 * (npar + 1) instead of 2 * npar. > > In the help page of logLik, it said: > '"df"' (*d*egrees of *f*reedom), giving the number of (estimated) > parameters in the model. > > The "df" is used by AIC() as npar, however, "df" is not number of > estimated parameters in the model, df - 1 is. Am I correct? > > Best wishes, > Jinsong > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] NLSR package newDeriv function
One approach is to compute things exact using the caracas package; see below. Best regards Søren > library(caracas) > f <- function(x,y){x+y} > def_sym(x,y,z) > f <- x+y^2+y*z^2 > f [caracas]: 2 2 x + y + y⋅z > > d1 <- der(f, c(x,y,z)) > d2 <- der2(f, c(x,y,z)) > > d1 [caracas]: ⎡ 2 ⎤ ⎣1 2⋅y + z 2⋅y⋅z⎦ > d2 [caracas]: ⎡0 00 ⎤ ⎢ ⎥ ⎢0 2 2⋅z⎥ ⎢ ⎥ ⎣0 2⋅z 2⋅y⎦ > > tex(d1) [1] "\\left[\\begin{matrix}1 & 2 y + z^{2} & 2 y z\\end{matrix}\\right]" > tex(d2) [1] "\\left[\\begin{matrix}0 & 0 & 00 & 2 & 2 z0 & 2 z & 2 y\\end{matrix}\\right]" > > as_expr(d1) expression(cbind(1, 2*y + z^2, 2*y*z)) > as_expr(d2) expression(rbind(cbind(0, 0, 0), cbind(0, 2, 2*z), cbind(0, 2*z, 2*y))) > On Wed, 2021-04-14 at 19:35 +, Debangan Dey wrote: > Hi, > > I am trying to solve a non-linear least square which has a function > from R^3 -> R. Is it possible to define gradient using newDeriv for a > 3-variate scalar function? > > I am trying to use the genD function in numDeriv package to define > numerical gradient and treat them as a function. So far, I have > failed to do it for simple function as follows � > > f <- function(x,y){x+y} > grad.f <- function(x,y){z <- c(x,y) > f2 <- function(z){f(z[1],z[2])} > gd <- genD(f2,z)$D[,1:length(z)] > return(gd) > } > newDeriv(f(x,y), grad.f(x,y)) > > This derivative definition is not working as the following error pops > up � > > fd <- fnDeriv(~ f(x,y), c("x",�y�)) > fd(c(1,2)) > Error in .grad[, "x"] <- grad.f(x) : > number of items to replace is not a multiple of replacement length > > > I know the above example would work if I just give expressions > instead of using grad function in numDeriv but I am trying to use > numDeriv::grad here to see if my toy example can be translated to the > bigger function I would later use it on. > > Thanks, > Debanga > > -- > Debangan Dey, > PhD Student in Biostatistics, > Johns Hopkins Bloomberg School of Public Health, > Baltimore, MD > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Installing bioconduction packages in connection with loading an R package
Dear all, My gRbase package imports functionality from the bioconductor packages graph, Rgraphviz and RBGL. To make installation of gRbase easy, I would like to have these bioconductor packages installed in connection with installation of gRbase, but to do so the user must use setRepositories() to make sure that R also installs packages from bioconductor. Having to call setRepositories causes what can perhaps be called an (unnecessary?) obstacle. Therefore I have been experimenting with deferring installation of these bioc-packages until gRbase is loaded the first time using .onAttach; please see my attempt below. However, if the bioc-packages are not installed I can not install gRbase so that does not seem to be a viable approach. (The bioc-packages appear as Imports: in DESCRIPTION). Can anyone tell if it is a futile approach and / or perhaps suggest a solution. (I would guess that there are many CRAN packages that use bioc-packages, so other people must have faced this challenge before). Thanks in advance. Best regards S�ren .onAttach<-function(libname, pkgname) { ## package startup check toinstall=c( "graph", "Rgraphviz", "RBGL" ) already_installed <- sapply(toinstall, function(pkg) requireNamespace(pkg, quietly=TRUE)) if (any(!already_installed)){ packageStartupMessage("Need to install the following package(s): ", toString(toinstall[!already_installed]), "\n") } ## install if needed if(!base::all(already_installed)){ if (!requireNamespace("BiocManager", quietly=TRUE)) install.packages("BiocManager") BiocManager::install(toinstall[!already_installed], dependencies=TRUE) } } [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 in optimize (related to naming the arguments)
Dear all, I am wondering if there is a minor bug in the optimimize function; please see below: --- > ## example taken from optimize documentation > f <- function (x, a) (x - a)^2 > xmin <- optimize(f, c(0, 1), tol = 0.0001, a = 1/3) > xmin $minimum [1] 0.333 $objective [1] 0 > ## if we change argument a to j things still work fine > f2 <- function (x, j) (x - j)^2 > xmin2 <- optimize(f2, c(0, 1), tol = 0.0001, j = 1/3) > xmin2 $minimum [1] 0.333 $objective [1] 0 > ## if we change argument a to i things fail > f3 <- function (x, i) (x - i)^2 > xmin3 <- optimize(f3, c(0, 1), tol = 0.0001, i = 1/3) Error in optimize(f3, c(0, 1), tol = 1e-04, i = 1/3) : 'xmin' not less than 'xmax' > xmin3 $minimum [1] 0.333 $objective [1] 0 > ##Same here > xmin3 <- optimize(f3, lower=0, upper=1, tol = 0.0001, i = 1/3) Error in f(arg, ...) (from #1) : argument "i" is missing, with no default > xmin3 $minimum [1] 0.333 $objective [1] 0 > ## a workaround is > xmin3 <- optimize(f3, interval=c(0, 1), tol = 0.0001, i = 1/3) > xmin3 $minimum [1] 0.333 $objective [1] 0 --- the problem is, I guess, due to the keyword 'interval' gets mixed up with 'i'. Has anyone experienced that? Best regards S�ren [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] consider running tools::compactPDF(gs_quality = "ebook")
Dear all, I run R CMD build --compact-vignettes="both" gRbase and/or R CMD build --compact-vignettes="gs+qpdf" gRbase and in the log from r-devel (on winbuilder) I get * checking sizes of PDF files under 'inst/doc' ... WARNING 'gs+qpdf' made some significant size reductions: compacted 'gRbase-arrays.pdf' from 421Kb to 115Kb consider running tools::compactPDF(gs_quality = "ebook") on these files According to "writing R extensions" things should be fine (I have gs and qpdf on my system): "The --compact-vignettes option will run tools::compactPDF over the PDF files in inst/doc (and its subdirectories) to losslessly compress them. This is not enabled by default (it can be selected by environment variable _R_BUILD_COMPACT_VIGNETTES_) and needs qpdf (http://qpdf.sourceforge.net/) to be available. " Can anyone please tell me what to do? Best regards Søren --- > sessionInfo() R version 3.4.4 (2018-03-15) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 16.04.4 LTS Matrix products: default BLAS: /usr/lib/libblas/libblas.so.3.6.0 LAPACK: /usr/lib/lapack/liblapack.so.3.6.0 locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] Rcpp_0.12.17shtools_1.0 markdown_0.8knitr_1.20 [5] rmarkdown_1.10 devtools_1.13.5 loaded via a namespace (and not attached): [1] lattice_0.20-35 digest_0.6.15 withr_2.1.2 [4] rprojroot_1.3-2 grid_3.4.4 backports_1.1.2 [7] magrittr_1.5evaluate_0.10.1 stringi_1.2.3 [10] curl_3.2RcppArmadillo_0.8.500.0 Matrix_1.2-14 [13] tools_3.4.4 RcppEigen_0.3.3.4.0 stringr_1.3.1 [16] compiler_3.4.4 memoise_1.1.0 htmltools_0.3.6 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 was the script editor introduced in Rgui for windows?
Dear all, Can anyone please tell me when the script editor was introduced in the Rgui on windows? (And/or where to look for a listing of changes throughout history). Best regards Søren __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Checking whether specific packages (from bioconductor) are installed when loading a package
Dear all, My package 'gRbase' uses three packages from Bioconductor and these are not automatically installed when gRbase is installed. My instructions (on the package webpage) to users are therefore to run: source(http://bioconductor.org/biocLite.R;); biocLite(c(graph,RBGL,Rgraphviz)) When loading gRbase, it is checked whether these Bioconductor packages are available, but I would like to add a message about how to install the packages if they are not. Does this go into .onAttach or .onLoad or elsewhere? Thanks in advance Søren __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Lme4 Package Help!
Actually, I believe that for a brief period (around 2006) lmer did return p-values (chisq-based), but then 2006 is a long time ago... If the question pertains p-values in the usual output of coef( summary( model ) ), I'll just mention that with doBy and pbkrtest you can do linest( model, diag(1, length(coef(model)) ) ) With the next release of doBy you do not need to specify the diag-stuff, but for now you have to. Cheers Søren |-Original Message- |From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] |On Behalf Of Ben Bolker |Sent: 9. november 2014 03:48 |To: r-h...@stat.math.ethz.ch |Subject: Re: [R] Lme4 Package Help! | |Doran, Harold HDoran at air.org writes: | | | Daniel | | Lmer has never returned p-values from a model summary; this is a | well-known and discussed issue. You must have post-processed the data | in some way to get the p-values. | | But it's worth noting that lmerTest does, and the way it works makes it |pretty hard to see that the results are not coming from vanilla lme4. If |this is what happened I wouldn't blame the OP for getting confused. | |__ |R-help@r-project.org mailing list |https://stat.ethz.ch/mailman/listinfo/r-help |PLEASE do read the posting guide http://www.R-project.org/posting- |guide.html |and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Testing general hypotheses on regression coefficients
AFAICS you are not testing a linear hypothesis (which is of the form Lb=b0 where L is a matrix and b=(a,B1,B2,B3,B3) is the parameter vector). If, for simplicity, your model is E(y) = a + bx then -a/b is the x-value for which y is zero. When you turn to estimates then u = -a/b is the ratio of two (typically correlated) normal variables and such a ratio is *not* normal. (Just think of the Cauchy distribution.) One approach is to calculate the approximate variance of u and then construct a Wald test or similar while hoping for the best. Alternatively one could perhaps try with a parametric bootstrap test. Just ideas. Good luck. Søren -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Chris Sent: 6. september 2014 04:17 To: r-h...@stat.math.ethz.ch Subject: [R] Testing general hypotheses on regression coefficients Hi. Say I have a model like y = a + B1*x1 + B2*x2 + B3*x3 + B4*x4 + e and I want to test H0: B2/B1 = 0 or H0: B2/B1=B4/B3 (whatever H1). How can I proceed? I now about car::linearHypothesis, but I can't figure out a way to do the tests above. Any hint? Thanks. C __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] degrees of freedom
As a supplement to Bens reply: The pbkrtest package allows calculation of degrees of freedom by the Kenward-Roger method; something like library(lme4) model1 - lmer(value~group + (1|animal), data=bip) summary(model1) anova(model1) model0 - update(model1, .~.-group) anova(model1, model0) library(pbkrtest) KRmodcomp(model1, model0) PBmodcomp(model1, model0) The doBy package provides facilities for calculating LSmeans (se the vignette) for groupwise comparisons (and so does the lsmeans) package. See also facilities in the multcomp packages. Cheers Søren -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ben Bolker Sent: 23. januar 2014 23:35 To: r-h...@stat.math.ethz.ch Subject: Re: [R] degrees of freedom Iain Gallagher iaingallagher at btopenworld.com writes: Hello List I have been asked to analyse some data for a colleague. The design consists of a two sets of animals First set of three - one leg is treated and the other is not under two different conditions (control overload are the same animals - control leg is control (!) for treated leg; Second set of three - one leg is treated and the other is not under two different conditions (high_fat and high_fat_overload are the same animals with high_fat being control leg for high_fat_overload). Ideally I'd like to find differences between the treatments. bip - structure(list(group = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L), .Label = c(control, overload, high_fat, high_fat_overload), class = factor), variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = BiP, class = factor), animal = structure(c(1L, 3L, 5L, 1L, 3L, 5L, 2L, 4L, 6L, 2L, 4L, 6L), .Label = c(rat1_c, rat1_hf, rat2_c, rat2_hf, rat3_c, rat3_hf), class = factor), value = c(404979.65625, 783511.8125, 677277.625, 1576900.375, 1460101.875, 1591022, 581313.75, 992724.1875, 1106941.5, 996600.375, 1101696.5, 1171004.375)), .Names = c(group, variable, animal, value), row.names = c(NA, 12L), class = data.frame) I chose to analyse this as a mixed effects model with treatment as a fixed effect and animal as random. library(lme4) model1 - lmer(value~group + (1|animal), data=bip) summary(model1) And then compare this to no treatment with: anova(model1) From this I wanted to work out whether 'treatment' was significantly affecting BiP levels by calculating the critical value of F for this design. I have 2 groups of animals and 3 animals per group. My calculation for the degrees of freedom for treatment is 4-1=3. I'm not sure about the degrees of freedom for the denominator though. Since I'm comparing a model with treatment to one without (i.e. the grand mean) would the df for my denominator be 6-1=5? So I'd then have: qf(0.95,3,5) for my critical F value? Best iain I started to answer this, but then realized I'd really recommend that you re-post this to r-sig-mixed-mod...@r-project.org. I have a couple of points for you to think about that might help: * since you only have two treatments, I think you can analyze this as a _paired_ model, that is, reduce the data to (treatment-control, i.e. overload - non_overload) for each animal. Then you'll have 6 data points, 3 in each group, and you can just do a regular 1-way ANOVA on them. * I *think* you've only got 1 df for treatment * You might also be able to handle this problem via aov() with an Error stratum Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] descriptive stats by cells in factorial design
The summaryBy function in the doBy package may help you. Regards Søren Sendt fra Samsung mobil Oprindelig meddelelse Fra: Mike Miller mbmille...@gmail.com Dato: Til: R-Help List r-h...@stat.math.ethz.ch Emne: [R] descriptive stats by cells in factorial design I'm looking for recommendations for a good way to do this. There must be a good function in some package... I have a 5-way factorial design, two levels per factor, so 32 cells, and I mostly just want the means and standard deviations for the contents of every cell. I can write a for loop, but maybe there is a nice way to show the model and get the results I want without having to do that. Similarly, it would be nice to also have the range and maybe some percentiles, if there is a function that would just pump them out. Finally, if something would draw a series of box plots for the cells of the factorial design, that could be nice to have. It seems like this sort of thing must already have been worked out. Thanks in advance. Mike -- Michael B. Miller, Ph.D. Minnesota Center for Twin and Family Research Department of Psychology University of Minnesota __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Vignettes do not appear on CRAN if files are placed in /vignette subdirectory - but they do appear if placed in /inst/doc
Dear all, In my gRbase package there are 3 vignettes placed in the /vignette subdirectory. These vignettes do not appear on http://cran.r-project.org/web/packages/gRbase/index.html and neither do they appear if I open a browser with help(gRbase). However, if instead I place the vignettes in /inst/doc then they will appear in the browser opened with help(gRbase) - and they also appear on CRAN. Is this how it should be or am I missing something? Best regards Søren sessionInfo() R version 3.0.1 Patched (2013-06-11 r62941) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252 [3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C [5] LC_TIME=Danish_Denmark.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] gRain_1.1-2 gRbase_1.6-10 graph_1.38.0 [4] igraph_0.6.5-2 RcppArmadillo_0.3.900.0 RcppEigen_0.3.1.2.1 [7] Matrix_1.0-12 lattice_0.20-15 Rcpp_0.10.3 [10] MASS_7.3-26 shTools_1.0 markdown_0.5.4 [13] knitr_1.2 loaded via a namespace (and not attached): [1] BiocGenerics_0.6.0 digest_0.6.3 evaluate_0.4.3 formatR_0.7 [5] grid_3.0.1 parallel_3.0.1 RBGL_1.36.2stats4_3.0.1 [9] stringr_0.6.2 tools_3.0.1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Vignettes do not appear on CRAN if files are placed in /vignette subdirectory - but they do appear if placed in /inst/doc
Sorry, yes it is plural - but changing to plural has no effect. Regards Søren -Original Message- From: Martin Morgan [mailto:mtmor...@fhcrc.org] Sent: 30. juni 2013 23:09 To: Søren Højsgaard Cc: R hELP (r-h...@stat.math.ethz.ch) Subject: Re: [R] Vignettes do not appear on CRAN if files are placed in /vignette subdirectory - but they do appear if placed in /inst/doc On 06/30/2013 01:31 PM, Søren Højsgaard wrote: Dear all, In my gRbase package there are 3 vignettes placed in the /vignette subdirectory. These vignettes do not appear on http://cran.r-project.org/web/packages/gRbase/index.html and neither do they appear if I open a browser with help(gRbase). the directory name is plural -- vignettes. Martin However, if instead I place the vignettes in /inst/doc then they will appear in the browser opened with help(gRbase) - and they also appear on CRAN. Is this how it should be or am I missing something? Best regards Søren sessionInfo() R version 3.0.1 Patched (2013-06-11 r62941) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252 [3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C [5] LC_TIME=Danish_Denmark.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] gRain_1.1-2 gRbase_1.6-10 graph_1.38.0 [4] igraph_0.6.5-2 RcppArmadillo_0.3.900.0 RcppEigen_0.3.1.2.1 [7] Matrix_1.0-12 lattice_0.20-15 Rcpp_0.10.3 [10] MASS_7.3-26 shTools_1.0 markdown_0.5.4 [13] knitr_1.2 loaded via a namespace (and not attached): [1] BiocGenerics_0.6.0 digest_0.6.3 evaluate_0.4.3 formatR_0.7 [5] grid_3.0.1 parallel_3.0.1 RBGL_1.36.2stats4_3.0.1 [9] stringr_0.6.2 tools_3.0.1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M1 B861 Phone: (206) 667-2793 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Vignettes do not appear on CRAN if files are placed in /vignette subdirectory - but they do appear if placed in /inst/doc
gRbase use graph, RBGL and Rgraphviz from bioconductor. My understanding is that if I put vignettes into /vignettes then R CMD build will build the vignettes and put them into /inst/doc and this works: gRbase/inst/ gRbase/inst/CITATION gRbase/inst/doc/ gRbase/inst/doc/gRbase-arrayops1.R gRbase/inst/doc/gRbase-arrayops1.Rnw gRbase/inst/doc/gRbase-arrayops1.pdf gRbase/inst/doc/gRbase-arrayops2.R gRbase/inst/doc/gRbase-arrayops2.Rnw gRbase/inst/doc/gRbase-arrayops2.pdf gRbase/inst/doc/gRbase-graphs.R gRbase/inst/doc/gRbase-graphs.Rnw gRbase/inst/doc/gRbase-graphs.pdf After installing I then get vignette(package=gRbase) no vignettes found sorenh@sorenh:~/docs/stat/Rdevel/gmwR-DEVEL/gRbaseDEVEL$ R --version R version 3.0.1 (2013-05-16) -- Good Sport Copyright (C) 2013 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) However, Martin Morgan reports that it works for him. I don't know what to make of this. Regards Søren -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: 1. juli 2013 00:45 To: Søren Højsgaard Cc: Martin Morgan; R hELP (r-h...@stat.math.ethz.ch) Subject: Re: [R] Vignettes do not appear on CRAN if files are placed in /vignette subdirectory - but they do appear if placed in /inst/doc On 13-06-30 5:28 PM, Søren Højsgaard wrote: Sorry, yes it is plural - but changing to plural has no effect. CRAN has had some problems building vignettes in cases where the vignette depends on packages that are not installed on CRAN. Could that be the problem? (They are working on fixing this.) My tables package has a vignette in the vignettes directory, and it shows up on CRAN, so if it is not the above, there may be other problems. I am currently involved in redoing the build/INSTALL code for vignettes (which is currently somewhat inconsistent), but I don't know when the new code will be ready. Duncan Murdoch Regards Søren -Original Message- From: Martin Morgan [mailto:mtmor...@fhcrc.org] Sent: 30. juni 2013 23:09 To: Søren Højsgaard Cc: R hELP (r-h...@stat.math.ethz.ch) Subject: Re: [R] Vignettes do not appear on CRAN if files are placed in /vignette subdirectory - but they do appear if placed in /inst/doc On 06/30/2013 01:31 PM, Søren Højsgaard wrote: Dear all, In my gRbase package there are 3 vignettes placed in the /vignette subdirectory. These vignettes do not appear on http://cran.r-project.org/web/packages/gRbase/index.html and neither do they appear if I open a browser with help(gRbase). the directory name is plural -- vignettes. Martin However, if instead I place the vignettes in /inst/doc then they will appear in the browser opened with help(gRbase) - and they also appear on CRAN. Is this how it should be or am I missing something? Best regards Søren sessionInfo() R version 3.0.1 Patched (2013-06-11 r62941) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252 [3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C [5] LC_TIME=Danish_Denmark.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] gRain_1.1-2 gRbase_1.6-10 graph_1.38.0 [4] igraph_0.6.5-2 RcppArmadillo_0.3.900.0 RcppEigen_0.3.1.2.1 [7] Matrix_1.0-12 lattice_0.20-15 Rcpp_0.10.3 [10] MASS_7.3-26 shTools_1.0 markdown_0.5.4 [13] knitr_1.2 loaded via a namespace (and not attached): [1] BiocGenerics_0.6.0 digest_0.6.3 evaluate_0.4.3 formatR_0.7 [5] grid_3.0.1 parallel_3.0.1 RBGL_1.36.2stats4_3.0.1 [9] stringr_0.6.2 tools_3.0.1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M1 B861 Phone: (206) 667-2793 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Vignettes do not appear on CRAN if files are placed in /vignette subdirectory - but they do appear if placed in /inst/doc
Yes, these packages are all installed. Søren -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: 1. juli 2013 01:59 To: Søren Højsgaard Cc: Martin Morgan; R hELP (r-h...@stat.math.ethz.ch) Subject: Re: [R] Vignettes do not appear on CRAN if files are placed in /vignette subdirectory - but they do appear if placed in /inst/doc On 13-06-30 7:54 PM, Søren Højsgaard wrote: gRbase use graph, RBGL and Rgraphviz from bioconductor. My understanding is that if I put vignettes into /vignettes then R CMD build will build the vignettes and put them into /inst/doc and this works: gRbase/inst/ gRbase/inst/CITATION gRbase/inst/doc/ gRbase/inst/doc/gRbase-arrayops1.R gRbase/inst/doc/gRbase-arrayops1.Rnw gRbase/inst/doc/gRbase-arrayops1.pdf gRbase/inst/doc/gRbase-arrayops2.R gRbase/inst/doc/gRbase-arrayops2.Rnw gRbase/inst/doc/gRbase-arrayops2.pdf gRbase/inst/doc/gRbase-graphs.R gRbase/inst/doc/gRbase-graphs.Rnw gRbase/inst/doc/gRbase-graphs.pdf After installing I then get vignette(package=gRbase) no vignettes found sorenh@sorenh:~/docs/stat/Rdevel/gmwR-DEVEL/gRbaseDEVEL$ R --version R version 3.0.1 (2013-05-16) -- Good Sport Copyright (C) 2013 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) However, Martin Morgan reports that it works for him. I don't know what to make of this. Do you have all of those packages installed at the time you install gRbase? If so, it may be a bug. As I said, installation code is being worked on. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Issue with Imports in NAMESPACE
Dear all, In my gRbase package I have up until now Depend-ed on RBGL (from Bioconductor), but good people have convinced me that I should use Import-it instead because I only use few functions from RBGL. In DESCRIPTION I therefore now have Imports: Matrix,RBGL In NAMESPACE I now have importFrom(RBGL, maxClique, is.triangulated, separates) The package compiles without complaints, but I have noticed that if I start a fresh R-session, then maxClique etc. from RBGL is NOT available for interactive use in my session: library(gRbase) maxClique Error: object 'maxClique' not found 1) Is this as it should be? 2) If yes, is there any other way in which maxClique can be imported for interactive use without Depend-ing the whole RBGL package? Best regards Søren __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Issue with Imports in NAMESPACE
Dear Duncan, Excellent, thanks! Maybe this is worth a remark in a future version of Writing R Extensions (including that those local copies are not exported again with exportPattern(^[[:alpha:]]+)). Thanks! Søren -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: 25. juni 2013 13:02 To: Søren Højsgaard Cc: R hELP (r-h...@stat.math.ethz.ch) Subject: Re: [R] Issue with Imports in NAMESPACE On 13-06-25 6:50 AM, Søren Højsgaard wrote: Dear all, In my gRbase package I have up until now Depend-ed on RBGL (from Bioconductor), but good people have convinced me that I should use Import-it instead because I only use few functions from RBGL. In DESCRIPTION I therefore now have Imports: Matrix,RBGL In NAMESPACE I now have importFrom(RBGL, maxClique, is.triangulated, separates) The package compiles without complaints, but I have noticed that if I start a fresh R-session, then maxClique etc. from RBGL is NOT available for interactive use in my session: library(gRbase) maxClique Error: object 'maxClique' not found 1) Is this as it should be? 2) If yes, is there any other way in which maxClique can be imported for interactive use without Depend-ing the whole RBGL package? The importFrom directive effectively makes local copies of those functions in your package (with the usual caveats that copies aren't as inefficient as you might think). If you want to export them, you need to add them to the exports list. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Issue with Imports in NAMESPACE
R CMD check does complain and I had to add \alias{maxClique} in an .Rd file (I did it this way to prevent downstream packages from failing). Regards Søren -Original Message- From: luke-tier...@uiowa.edu [mailto:luke-tier...@uiowa.edu] Sent: 25. juni 2013 15:50 To: Duncan Murdoch Cc: Søren Højsgaard; R hELP (r-h...@stat.math.ethz.ch) Subject: Re: [R] Issue with Imports in NAMESPACE On Tue, 25 Jun 2013, Duncan Murdoch wrote: On 13-06-25 7:14 AM, Søren Højsgaard wrote: Dear Duncan, Excellent, thanks! Maybe this is worth a remark in a future version of Writing R Extensions (including that those local copies are not exported again with exportPattern(^[[:alpha:]]+)). It is mentioned that they can be exported. The fact that exportPattern doesn't see them might be a bug. I don't think it's a bug -- including all imports would usually bring in way too much. In general re-exporting is probably not such a great idea since the help system isn't aware of the import/export chain. I don't know if R CMD check complains if you don't provide your own help page; if it doesn't it probably should. I also don't recall if we have a mechanism for such a help page on an import/export to just link to the real page. Best, luke Duncan Thanks! Søren -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: 25. juni 2013 13:02 To: Søren Højsgaard Cc: R hELP (r-h...@stat.math.ethz.ch) Subject: Re: [R] Issue with Imports in NAMESPACE On 13-06-25 6:50 AM, Søren Højsgaard wrote: Dear all, In my gRbase package I have up until now Depend-ed on RBGL (from Bioconductor), but good people have convinced me that I should use Import-it instead because I only use few functions from RBGL. In DESCRIPTION I therefore now have Imports: Matrix,RBGL In NAMESPACE I now have importFrom(RBGL, maxClique, is.triangulated, separates) The package compiles without complaints, but I have noticed that if I start a fresh R-session, then maxClique etc. from RBGL is NOT available for interactive use in my session: library(gRbase) maxClique Error: object 'maxClique' not found 1) Is this as it should be? 2) If yes, is there any other way in which maxClique can be imported for interactive use without Depend-ing the whole RBGL package? The importFrom directive effectively makes local copies of those functions in your package (with the usual caveats that copies aren't as inefficient as you might think). If you want to export them, you need to add them to the exports list. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Luke Tierney Chair, Statistics and Actuarial Science Ralph E. Wareham Professor of Mathematical Sciences University of Iowa Phone: 319-335-3386 Department of Statistics andFax: 319-335-3017 Actuarial Science 241 Schaeffer Hall email: luke-tier...@uiowa.edu Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Built-in function for extracting mantissa and exponent of a numeric
Dear all, Given a number x-1.234e12 is there a built-in function for extracting 1.234 and 12 ? The following hack seems clumpsy: a-strsplit(format(x, scientific=T),e)[[1]] a [1] 1.234 +12 as.numeric(a[1]) [1] 1.234 as.integer(a[2]) [1] 12 Regards Søren __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] evaluation of equations from Ryacas
Dear Erin, Not exactly elegant, but e-expression(list(R == 100 * (1 - 2 * y/1))) ee - e[[1]][2] ee (R == 100 * (1 - 2 * y/1))() eval(parse(text=(substring(paste(ee), 5))), list(y=5)) [1] 99.9 Regards Søren -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Erin Hodgess Sent: 19. juni 2013 07:03 To: R help Subject: [R] evaluation of equations from Ryacas Hello again. Now I have the following: xx [1] Solve(1 - R/100==(2*y)/1,R) yacas(xx) expression(list(R == 100 * (1 - 2 * y/1))) I would like to put in a value for y and obtain R. I've tried more stuff with eval and Eval, but no luck yet. Any suggestions would be much appreciated. Thanks, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Ryacas loads but yacas has an error
Dear Erin, I don't have solution, but there is a remark on connection issues at http://code.google.com/p/ryacas/ An alternative could be to look at the rSymPy or rmathpiper packages which may do what you want. Regards Søren -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Erin Hodgess Sent: 19. juni 2013 17:50 To: R help Subject: [R] Ryacas loads but yacas has an error Hello yet again, R People: I was working with Ryacas and yacas last night and all was well. Now this morning, I keep getting the following: a - Sym(a) a Error in summary.connection(x) : invalid connection When I go to yacas from the command line, it works fine. Any suggestions, please? I'm thinking that a port might be open, but here I have: showConnections() description class mode text isopen can read can write I'm working with R-3.0.1 on Windows 7. Thanks, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Modifying a function programmatically
Dear list # I have a function ff - function(a,b=2,c=4){a+b+c} # which I programmatically want to modify to a more specialized function in which a is replaced by 1 ff1 - function(b=2,c=4){1+b+c} # I do as follows: vals - list(a=1) (expr1 - as.expression(body(ff))) expression({ a + b + c }) (expr2 - do.call(substitute, list(expr1[[1]], vals))) { 1 + b + c } # This works, eval(expr2, list(b=10,c=12)) [1] 23 # - but I would like a function. Hence I do: ll - alist(b=, c=, eval(expr2)) ff2 - as.function(ll) ff2(b=10,c=12) [1] 23 # BUT I am only half-way where I want to be because the alist(b=, c=, ...) # requires me plugin the remaining formals by hand. I do: newformals -setdiff(names(formals(ff)), names(vals)) vv - vector(list, length(newformals)) names(vv) - newformals (hh - c(vv, expr2)) $b NULL $c NULL [[3]] { 1 + b + c } (ff3 - as.function(hh)) function (b = NULL, c = NULL) { 1 + b + c } ff3(10,12) [1] 23 # Hence I get the function that returns what I want (given the correct input) # but the arguments will have default values that I don't want. # I want to retain the original default values (if any) ff1() [1] 7 ff3() numeric(0) I have two questions: 1) How to fix the above? 2) Aren't there more elegant alternatives? Any help would be appreciated. Regards Søren __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Modifying a function programmatically
No, this is not really what I want. But I have (later) realized that what I am looking for can be achieved as shown below. I am just not sure how bullet-proof the solution is. Suggestions are welcome! Regards Søren -- specialize - function(ff, vals){ expr1 - as.expression(body(ff)) expr2 - do.call(substitute, list(expr1[[1]], vals)) gg - formals(ff) idx -match(names(vals), names(gg)) gg - gg[-idx] as.function(c(gg, expr2)) } ff - function(a,b=2,c=4){a+b+c} (ans-specialize(ff, list(a=1))) function (b = 2, c = 4) { 1 + b + c } environment: 0x08b51c68 ans() [1] 7 ans(b=10) [1] 15 (ans-specialize(rnorm, list(n=10))) function (mean = 0, sd = 1) .Internal(rnorm(10, mean, sd)) environment: 0x08b5a0b8 ans() [1] 0.1783645319 2.1151344735 -0.6744270178 0.0009751497 -0.1477708270 0.1710790055 [7] -0.0064331250 0.5935787352 -0.1426050990 -0.1390478788 ans(sd=.0001) [1] 1.386604e-06 -6.616540e-05 6.592326e-05 -1.299638e-04 1.322658e-05 -4.515388e-05 [7] -2.809639e-05 -5.719492e-05 1.554319e-04 -1.186992e-04 -Original Message- From: Pascal Oettli [mailto:kri...@ymail.com] Sent: 4. februar 2013 11:11 To: Søren Højsgaard Cc: r-help@r-project.org Subject: Re: [R] Modifying a function programmatically Hi, Is it what you are looking for? ff - function(a,b,c){a+b+c} ff(1,10,12) [1] 23 ff(589,2,4) [1] 595 HTH, Pascal Le 04/02/2013 19:00, Søren Højsgaard a écrit : Dear list # I have a function ff - function(a,b=2,c=4){a+b+c} # which I programmatically want to modify to a more specialized function in which a is replaced by 1 ff1 - function(b=2,c=4){1+b+c} # I do as follows: vals - list(a=1) (expr1 - as.expression(body(ff))) expression({ a + b + c }) (expr2 - do.call(substitute, list(expr1[[1]], vals))) { 1 + b + c } # This works, eval(expr2, list(b=10,c=12)) [1] 23 # - but I would like a function. Hence I do: ll - alist(b=, c=, eval(expr2)) ff2 - as.function(ll) ff2(b=10,c=12) [1] 23 # BUT I am only half-way where I want to be because the alist(b=, c=, ...) # requires me plugin the remaining formals by hand. I do: newformals -setdiff(names(formals(ff)), names(vals)) vv - vector(list, length(newformals)) names(vv) - newformals (hh - c(vv, expr2)) $b NULL $c NULL [[3]] { 1 + b + c } (ff3 - as.function(hh)) function (b = NULL, c = NULL) { 1 + b + c } ff3(10,12) [1] 23 # Hence I get the function that returns what I want (given the correct input) # but the arguments will have default values that I don't want. # I want to retain the original default values (if any) ff1() [1] 7 ff3() numeric(0) I have two questions: 1) How to fix the above? 2) Aren't there more elegant alternatives? Any help would be appreciated. Regards Søren __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Modifying a function programmatically
Dear Gabor, Thanks for pointing me to this; didn't know the Curry function. For what it is worth, the two approaches perform somewhat differently in terms of computing time (my specialize function is given at the end): library(functional) ## EXAMPLE 1 ff - function(a,b=2,c=4){a+b+c} ff1 - specialize(ff, vals=list(a=1,bb=123)) ff2 - Curry(ff, a = 1) rbenchmark::benchmark(ff1(b=10), ff2(b=10), replications=10) test replications elapsed relative user.self sys.self user.child sys.child 1 ff1(b = 10) 100.391.000 0.390 NA NA 2 ff2(b = 10) 100.812.077 0.790 NA NA ## EXAMPLE 2 gg - rnorm gg1 - specialize(gg, list(n=10)) gg2 - Curry(gg, n=1000) rbenchmark::benchmark(gg1(), gg2(), replications=10) test replications elapsed relative user.self sys.self user.child sys.child 1 gg1() 100.531.000 0.53 0.00 NANA 2 gg2() 109.25 17.453 9.22 0.01 NANA where specialize - function(ff, vals){ expr1 - as.expression(body(ff)) expr2 - do.call(substitute, list(expr1[[1]], vals)) gg - formals(ff) idx -match(names(vals), names(gg)) idx - idx[!is.na(idx)] if (length(idx)0){ gg - gg[-idx]} as.function(c(gg, expr2)) } Best regards Søren -Original Message- From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Sent: 4. februar 2013 17:31 To: Søren Højsgaard Cc: r-help@r-project.org Subject: Re: [R] Modifying a function programmatically On Mon, Feb 4, 2013 at 5:00 AM, Søren Højsgaard sor...@math.aau.dk wrote: Dear list # I have a function ff - function(a,b=2,c=4){a+b+c} # which I programmatically want to modify to a more specialized function in which a is replaced by 1 ff1 - function(b=2,c=4){1+b+c} This a currying operation. Try: library(functional) ff1 - Curry(ff, a = 1) # test identical(ff1(2, 4), ff(1, 2, 4)) # TRUE -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Reading extremly large comma separated files?
The sqldf package may be of help to you. Regards Søren -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Öhagen Patrik Sent: 19. december 2012 10:48 To: R hELP Subject: [R] Reading extremly large comma separated files? Dear List, Are there any tricks or wise suggestions on how to import huge comma separated files into R? We have used the ordinary read syntax but it takes forever Thank you in advance! Cheers, Patrik __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Dispatching on a dgCMatrix does not work.
I represent a graph as an adjacency matrix of class dgCMatrix (from the Matrix package). xx 5 x 5 sparse Matrix of class dgCMatrix a b c d e a . 1 1 . . b 1 . 1 . . c 1 1 . 1 1 d . . 1 . 1 e . . 1 1 . To check if the matrix defines and undirected graph, I have made the following functions/methods: is.UG - function (object) { UseMethod(is.UG) } is.UG.dgCMatrix - function (object) { is.adjMAT(object) (max(abs(t(object) - object)) == 0) } Note: 1) is.adjMAT is homegrown and 2) I know there is an isSymmetric method, but I can't get that to work either. These functions are in a package and when I load the package I get: is.UG(xx) Error in t.default(object) : argument is not a matrix is.UG.dgCMatrix(xx) Error in t.default(object) : argument is not a matrix Interestingly, if I copy and past the definitions above into an R-session things do work: is.UG - function (object) { +UseMethod(is.UG) + } is.UG.dgCMatrix - function (object) { + is.adjMAT(object) (max(abs(t(object) - object)) == 0) + } is.UG(xx) [1] TRUE is.UG.dgCMatrix(xx) [1] TRUE Can anyone help here? Best regards Søren xx - new(dgCMatrix , i = c(1L, 2L, 0L, 2L, 0L, 1L, 3L, 4L, 2L, 4L, 2L, 3L) , p = c(0L, 2L, 4L, 8L, 10L, 12L) , Dim = c(5L, 5L) , Dimnames = list(c(a, b, c, d, e), c(a, b, c, d, e)) , x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) , factors = list() __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Having two different versions of a package in the same R installation
Dear list, I am making some comparisons of two versions of the lme4 package: The CRAN version and the R-Forge version. For the moment I have two different R installations, each with a different version of lme4. However it would be convenient if I could have the same version within the same R installation such that I can run a code chunk on one lme4 version and immediately after run the same code chunk on another lme4 version. Does anyone know if this is possible? Best regards Søren __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Having two different versions of a package in the same R installation
I don't know if it would work but a kludgy attempt would be to install lme4 from CRAN, rename the lme4 directory in library to lme4cran; then install lme4 from R-forge and rename the lme4 directory to lme4forge. Then create a script flexible script that would copy one of the directories to a directory called lme4 on the fly. I don't know if it would work, but I just wonder if there would possibly a more elegant way. Regards Søren -Original Message- From: Greg Snow [mailto:538...@gmail.com] Sent: 2. oktober 2012 22:27 To: Søren Højsgaard Cc: r-help@r-project.org Subject: Re: [R] Having two different versions of a package in the same R installation So if you have both loaded in the same instance of R, how will R know which version of lmer or other functions that you want to run? It seems cleanest to me to have the 2 different instances of R running like you do now. The other option would be to change all the names (exported ones anyways) in one version and change that package name as well. Then you would have 2 different package names with different exported function names. On Tue, Oct 2, 2012 at 2:18 PM, Søren Højsgaard sor...@math.aau.dk wrote: Dear list, I am making some comparisons of two versions of the lme4 package: The CRAN version and the R-Forge version. For the moment I have two different R installations, each with a different version of lme4. However it would be convenient if I could have the same version within the same R installation such that I can run a code chunk on one lme4 version and immediately after run the same code chunk on another lme4 version. Does anyone know if this is possible? Best regards Søren __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] eval inside a function call in connection with updating the data slot in the call of lmer
Dear list, Given a linear mixed model (from lme4) I want to 1) first change the input dataset and then 2) change the model formula. I want this to happen in a function call; Please see below. Options 1) and 2) below work whereas 3) fails with the message foo() Error in is.data.frame(data) : object 'beets2' not found Question: What is it one must to in case 3) to have R look inside the function to figure out what beets2 is? Best regards Søren library(pbkrtest) data(beets) lgs- lmer(sugpct~block+sow+harvest+(1|block:harvest), data=beets, REML=F) foo - function(){ ## 1) beets2 - transform(beets, yy = sugpct * yield) ma1- lmer(yy~block+sow+harvest+(1|block:harvest), data=beets2, REML=F) ma0- update(ma1, yy~.) ## 2) cl - getCall(lgs) cl[[data]] - beets2 mb1 - eval(cl) mb0 - update(mb1, yy~.) mb0 ## 3) cl - getCall(lgs) cl[[data]] - as.name(beets2) mc1 - eval(cl) mc0 - update(mc1, yy~.) mc0 } foo() __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Some kind of inverse of names
Is this what you want?: li - list(a=1, b=2, c=3, d=4) li $a [1] 1 $b [1] 2 $c [1] 3 $d [1] 4 unlist(li) a b c d 1 2 3 4 unname(unlist(li)) [1] 1 2 3 4 Regards Søren -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Julio Sergio Santana Sent: 21. august 2012 00:20 To: r-help@r-project.org Subject: [R] Some kind of inverse of names I wonder if there exists some kind of inverse of the names primitive in R. Let me explain what do I mean: If I create a list: - li - list(a=1, b=2, c=3, d=4) then I can have: - names(li) [1] a b c d which is, I guess, some kind of vector, since - typeof(names(li)) [1] character however, I haven't seen something that allows me to get the other side, i.e., the values. Something like: -VALUES(li) [1] 1 2 3 4 Do you have any comments on this? Thanks, - Sergio. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Symbolic computation in R-solving system of equations
Ryacas provides an interface to yacas from R. So my suggestion is to search the web to see if yacas can solve your specific problem. Regards Søren -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of jpm miao Sent: 16. august 2012 04:42 To: r-help Subject: [R] Symbolic computation in R-solving system of equations Hi, To my knowledge, Ryacas can do symbolic computation in R, like Mathematica or Maple. I wonder if it (or any other R package) can solve symbolically a system of equations? I have a system of four equations in four variables (non-linear, but not very hard to solve) and wonder if Ryacas or any other package can do it. I do not find the solution in Ryacas. Can it find a symbolic solution to a linear system? Thanks, Miao [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Creating sparse matrix of type dgCMatrix directly
I want to create a sparse matrix of type dgCMatrix using the Matrix package (and the matrix must be of this type even if other more compact representations may exist). I do library(Matrix) m1-Matrix(rep(1,4),nrow=2,ncol=2,sparse=T) m1 2 x 2 sparse Matrix of class dsCMatrix [1,] 1 1 [2,] 1 1 To convert m1, I do as(m1, dgCMatrix) 2 x 2 sparse Matrix of class dgCMatrix [1,] 1 1 [2,] 1 1 Is it possible to construct a dgCMatrix directly i.e. without going through the additional as() step above? Best regards Søren __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating sparse matrix of type dgCMatrix directly
-Original Message- From: dmba...@gmail.com [mailto:dmba...@gmail.com] On Behalf Of Douglas Bates Sent: 28. juli 2012 20:36 To: Søren Højsgaard Cc: r-help@r-project.org Subject: Re: [R] Creating sparse matrix of type dgCMatrix directly On Sat, Jul 28, 2012 at 7:26 AM, Søren Højsgaard sor...@math.aau.dk wrote: I want to create a sparse matrix of type dgCMatrix using the Matrix package (and the matrix must be of this type even if other more compact representations may exist). I do library(Matrix) m1-Matrix(rep(1,4),nrow=2,ncol=2,sparse=T) m1 2 x 2 sparse Matrix of class dsCMatrix [1,] 1 1 [2,] 1 1 To convert m1, I do as(m1, dgCMatrix) 2 x 2 sparse Matrix of class dgCMatrix [1,] 1 1 [2,] 1 1 Is it possible to construct a dgCMatrix directly i.e. without going through the additional as() step above? The Matrix function is a high-level function that is designed to produce a compact and informative representation of its arguments. That's why it checks for symmetry, triangularity, etc. To decide how to bypass these checks it would be useful to know what you are starting with. Will it be a dense matrix or a triplet representation or ...? [] Dear Doug, [] I use sparse matrices to represent graphs so the matrices contain zeros and non-zeros (in most cases ones). I need the matrices to be of the dgCMatrix type because these matrices can be used as sparse matrices in the RcppEigen package. For now I have created my own dgCMatrix() function doing what I've sketched above, but there is - as you also indicate - an overhead in the checks in the Matrix() function, and also an overhead in using as(). Regards Søren __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Indexing matrices from the Matrix package with [i, j] seems to be very slow. Are there faster alternatives?
Dear Duncan Thanks for your suggestion, but I really need sparse matrices: I have implemented various graph algorithms based on adjacency matrices. For large graphs, storing all the 0's in an adjacency matrices become uneconomical, and therefore I thought I would use sparse matrices but the speed of [i,j] will slow down the algorithms. However, using RcppEigen it is possible to mimic [i,j] with a slowdown of only a factor 16 which is much better than what is obtained when using [i,j]: benchmark(lookup(mm,`[`), lookup(MM,`[`), lookup(MM, Xiijj), + columns=c(test, replications, elapsed, relative), replications=5) test replications elapsed relative 1 lookup(mm, `[`)50.05 1.0 2 lookup(MM, `[`)5 23.54470.8 3 lookup(MM, Xiijj)50.84 16.8 The code for producing the result is given below. Best regards, Søren - library(inline) library(RcppEigen) library(rbenchmark) library(Matrix) src - ' using namespace Rcpp; typedef Eigen::SparseMatrixdouble MSpMat; const MSpMat X(asMSpMat(XX_)); int i = asint(ii_)-1; int j = asint(jj_)-1; double ans = X.coeff(i,j); return(wrap(ans)); ' Xiijj - cxxfunction(signature(XX_=matrix, ii_=integer, jj_=integer), body=src, plugin=RcppEigen) mm - matrix(c(1,0,0,0,0,0,0,0), nr=100, nc=100) MM - as(mm, Matrix) object.size(mm) object.size(MM) lookup - function(mat, func){ for (i in 1:nrow(mat)){ for (j in 1:ncol(mat)){ v-func(mat,i,j) } } } benchmark(lookup(mm,`[`), lookup(MM,`[`), lookup(MM, Xiijj), columns=c(test, replications, elapsed, relative), replications=5) -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: 25. juni 2012 11:27 To: Søren Højsgaard Cc: r-help@r-project.org Subject: Re: [R] Indexing matrices from the Matrix package with [i, j] seems to be very slow. Are there faster alternatives? On 12-06-24 4:50 PM, Søren Højsgaard wrote: Dear all, Indexing matrices from the Matrix package with [i,j] seems to be very slow. For example: library(rbenchmark) library(Matrix) mm- matrix(c(1,0,0,0,0,0,0,0), nr=20, nc=20) MM- as(mm, Matrix) lookup- function(mat){ for (i in 1:nrow(mat)){ for (j in 1:ncol(mat)){ mat[i,j] } } } benchmark(lookup(mm), lookup(MM), columns=c(test, replications, elapsed, relative), replications=50) test replications elapsed relative 1 lookup(mm) 500.01 1 2 lookup(MM) 508.77 877 I would have expected a small overhead when indexing a matrix from the Matrix package, but this result is really surprising... Does anybody know if there are faster alternatives to [i,j] ? There's also a large overhead when indexing a dataframe, though Matrix appears to be slower. It's designed to work on whole matrices at a time, not single entries. So I'd suggest that if you need to use [i,j] indexing, then try to arrange your code to localize the access, and extract a submatrix as a regular fast matrix first. (Or if it will fit in memory, convert the whole thing to a matrix just for the access. If I just add the line mat - as.matrix(mat) at the start of your lookup function, it becomes several hundred times faster.) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Indexing matrices from the Matrix package with [i, j] seems to be very slow. Are there faster alternatives?
Duncan, I should probably add that I am aware that my code is not the solution and also that the relative gain of my code probably decreases with the problem size until eventually it will perform worse that [i,j] (because of copying I suppose). So my point is just: It would just be nice if [i,j] was faster... Regards Søren PS: For a 2000 x 2000 matrix I get: test replications elapsed relative 1 lookup(mm, `[`) 514.85 1.00 2 lookup(MM, Xiijj)5 133.66 9.000673 Using the modified code src - ' using namespace Rcpp; typedef Eigen::MappedSparseMatrixdouble MSpMat; const MSpMat X(asMSpMat(XX_)); int i = asint(ii_)-1; int j = asint(jj_)-1; double ans = X.coeff(i,j); return(wrap(ans)); ' -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Søren Højsgaard Sent: 27. juni 2012 01:20 To: Duncan Murdoch Cc: r-help@r-project.org Subject: Re: [R] Indexing matrices from the Matrix package with [i, j] seems to be very slow. Are there faster alternatives? Dear Duncan Thanks for your suggestion, but I really need sparse matrices: I have implemented various graph algorithms based on adjacency matrices. For large graphs, storing all the 0's in an adjacency matrices become uneconomical, and therefore I thought I would use sparse matrices but the speed of [i,j] will slow down the algorithms. However, using RcppEigen it is possible to mimic [i,j] with a slowdown of only a factor 16 which is much better than what is obtained when using [i,j]: benchmark(lookup(mm,`[`), lookup(MM,`[`), lookup(MM, Xiijj), + columns=c(test, replications, elapsed, relative), + replications=5) test replications elapsed relative 1 lookup(mm, `[`)50.05 1.0 2 lookup(MM, `[`)5 23.54470.8 3 lookup(MM, Xiijj)50.84 16.8 The code for producing the result is given below. Best regards, Søren - library(inline) library(RcppEigen) library(rbenchmark) library(Matrix) src - ' using namespace Rcpp; typedef Eigen::SparseMatrixdouble MSpMat; const MSpMat X(asMSpMat(XX_)); int i = asint(ii_)-1; int j = asint(jj_)-1; double ans = X.coeff(i,j); return(wrap(ans)); ' Xiijj - cxxfunction(signature(XX_=matrix, ii_=integer, jj_=integer), body=src, plugin=RcppEigen) mm - matrix(c(1,0,0,0,0,0,0,0), nr=100, nc=100) MM - as(mm, Matrix) object.size(mm) object.size(MM) lookup - function(mat, func){ for (i in 1:nrow(mat)){ for (j in 1:ncol(mat)){ v-func(mat,i,j) } } } benchmark(lookup(mm,`[`), lookup(MM,`[`), lookup(MM, Xiijj), columns=c(test, replications, elapsed, relative), replications=5) -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: 25. juni 2012 11:27 To: Søren Højsgaard Cc: r-help@r-project.org Subject: Re: [R] Indexing matrices from the Matrix package with [i, j] seems to be very slow. Are there faster alternatives? On 12-06-24 4:50 PM, Søren Højsgaard wrote: Dear all, Indexing matrices from the Matrix package with [i,j] seems to be very slow. For example: library(rbenchmark) library(Matrix) mm- matrix(c(1,0,0,0,0,0,0,0), nr=20, nc=20) MM- as(mm, Matrix) lookup- function(mat){ for (i in 1:nrow(mat)){ for (j in 1:ncol(mat)){ mat[i,j] } } } benchmark(lookup(mm), lookup(MM), columns=c(test, replications, elapsed, relative), replications=50) test replications elapsed relative 1 lookup(mm) 500.01 1 2 lookup(MM) 508.77 877 I would have expected a small overhead when indexing a matrix from the Matrix package, but this result is really surprising... Does anybody know if there are faster alternatives to [i,j] ? There's also a large overhead when indexing a dataframe, though Matrix appears to be slower. It's designed to work on whole matrices at a time, not single entries. So I'd suggest that if you need to use [i,j] indexing, then try to arrange your code to localize the access, and extract a submatrix as a regular fast matrix first. (Or if it will fit in memory, convert the whole thing to a matrix just for the access. If I just add the line mat - as.matrix(mat) at the start of your lookup function, it becomes several hundred times faster.) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained
Re: [R] rgraphviz problem
Dear Anton, You may find the description on http://people.math.aau.dk/~sorenh/software/gR/index.html helpful. Regards -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Anton Gerostathos Sent: 24. juni 2012 14:28 To: r-help@r-project.org Subject: [R] rgraphviz problem Hello I desperately need help with installing the Rgraphviz package under windows 7. Please forget my ignorance of basic topics, I’m a psychiatrist trying to use text mining to analyse psychiatric reports for criminal courts, statistics and machine learning are within my reach but R environnement subtleties not really... I have read existing posts on rgraphviz installation problems that I have also encountered (i.e. R help - Rgraphviz installation problem) but after correcting these I get the following message – differences from problem posted in bold : Error : .onLoad failed in loadNamespace() for 'Rgraphviz', details: call: value[[3L]](cond) error: unable to load shared object C:/Users/User/Documents/R/win-library/2.15/Rgraphviz/libs/x64/Rgraphviz.dll' LoadLibrary failure: %1 is not a valid win32 application I understand that the problem can be related to the x64 version. So I copied the i386 version of the library in the path mentionned, replacing the x64 version, but new failure and same message received. I do not know how to change the path specified when loading rgraphviz neither whether this could change something. I would really appreciate any kind of help A Gerostathos [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rgraphviz problem
Perhaps you could try to see if you can get the 32 bit version to work AND you could also report the result of running sessionInfo() in your mail. Regards Søren -Original Message- From: Anton Gerostathos [mailto:antonios.gerostat...@windowslive.com] Sent: 24. juni 2012 18:43 To: Søren Højsgaard; r-help@r-project.org Subject: Re: [R] rgraphviz problem Dear Søren, thank you for the additional description. Through the link provided I got the idea to try the zip packages of Rgraphviz for installation. After an additional problem with the x64 version, finally resolved, I am now getting stuck with the following message when trying to load Rgraphviz: Error in get(hookname, envir = env, inherits = FALSE) : unable to allocate a memory bloc of 2.8 Go any ideas? Anton -Message d'origine- From: Højsgaard Sent: Sunday, June 24, 2012 2:49 PM To: Anton Gerostathos ; r-help@r-project.org Subject: RE: [R] rgraphviz problem Dear Anton, You may find the description on http://people.math.aau.dk/~sorenh/software/gR/index.html helpful. Regards -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Anton Gerostathos Sent: 24. juni 2012 14:28 To: r-help@r-project.org Subject: [R] rgraphviz problem Hello I desperately need help with installing the Rgraphviz package under windows 7. Please forget my ignorance of basic topics, I’m a psychiatrist trying to use text mining to analyse psychiatric reports for criminal courts, statistics and machine learning are within my reach but R environnement subtleties not really... I have read existing posts on rgraphviz installation problems that I have also encountered (i.e. R help - Rgraphviz installation problem) but after correcting these I get the following message – differences from problem posted in bold : Error : .onLoad failed in loadNamespace() for 'Rgraphviz', details: call: value[[3L]](cond) error: unable to load shared object C:/Users/User/Documents/R/win-library/2.15/Rgraphviz/libs/x64/Rgraphviz.dll' LoadLibrary failure: %1 is not a valid win32 application I understand that the problem can be related to the x64 version. So I copied the i386 version of the library in the path mentionned, replacing the x64 version, but new failure and same message received. I do not know how to change the path specified when loading rgraphviz neither whether this could change something. I would really appreciate any kind of help A Gerostathos [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Indexing matrices from the Matrix package with [i, j] seems to be very slow. Are there faster alternatives?
Dear all, Indexing matrices from the Matrix package with [i,j] seems to be very slow. For example: library(rbenchmark) library(Matrix) mm - matrix(c(1,0,0,0,0,0,0,0), nr=20, nc=20) MM - as(mm, Matrix) lookup - function(mat){ for (i in 1:nrow(mat)){ for (j in 1:ncol(mat)){ mat[i,j] } } } benchmark(lookup(mm), lookup(MM), columns=c(test, replications, elapsed, relative), replications=50) test replications elapsed relative 1 lookup(mm) 500.01 1 2 lookup(MM) 508.77 877 I would have expected a small overhead when indexing a matrix from the Matrix package, but this result is really surprising... Does anybody know if there are faster alternatives to [i,j] ? Best regards Søren __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Help with ordering values
Will y[order(match(y,x))] [1] 9 8 11 2 1 do? Regards Søren -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Lars Bishop Sent: 20. maj 2012 01:05 To: r-help@r-project.org Subject: [R] Help with ordering values Hi, Is it possible to use x and y below to produce the vector shown in desired.result (which represents the values in y ordered according to the order specified by x)? Ideally the solution must be efficient in terms of timing as I'm dealing with *very* long vectors. x - c(7, 6, 5, 9, 4, 14, 8, 12, 10, 11, 2, 13, 3, 1) y - c(1, 2, 9, 8, 11) desired.result - c(9, 8, 11, 2, 1) Thanks, Lars. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Imputing missing values using LSmeans (i.e., population marginal means) - advice in R?
Dear Jenn, Could you please provide a reproducible example. In your case, you could for example provide the data (using dput(dat)). Regards Søren -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jenn Barrett Sent: 6. april 2012 18:30 To: Andy Liaw Cc: r-help@r-project.org Subject: Re: [R] Imputing missing values using LSmeans (i.e., population marginal means) - advice in R? Thanks Andy. I did read that posting, but didn't find that it answered my questions. Ok - so I've confirmed that I can use popMeans in the doBy package to obtain the LSmeans as described in my e-mail below; however, the output has me puzzled. Recall that my data consists of counts at various sites (n=93 this time) over about 35 years. Each site was only counted once per year; however, not all sites were counted in all years (i.e., data is unbalanced). Sample code is as follows: dat-read.csv(CountData.csv”) dat$COUNTYR_F-as.factor(dat$COUNT_YR) # Convert year variable to factor lmMod-lm(log(COUNT+0.5)~SITE + COUNTYR_F, data=dat) # Run lm on log transformed counts library(doBy) pM-popMeans(lmMod, c(SITE,COUNTYR_F)) LMest-exp(pM$Estimate) # Transform LS estimates back to count and save to a vector head(LMest,10) [1] 2.3006217 0.7012738 0.6707810 8.4331212 4.6810141 0.5902387 1.2535870 903.2004994 31.7064744 351.7324390 # e.g., compare above output to actual counts: 2, 0, 0, NA, 14, 0, NA, 1031, NA, NA # This output looks alright. However: pM.year-popMeans(lmMod,COUNTYR_F) LMest.year-exp(pM.year$Estimate) LMest.year [1] 35.94605 52.21187 38.26182 45.04494 48.26065 31.57805 38.20253 29.08914 27.01732 32.25929 32.54706 25.29704 31.99606 35.86583 [...] range(LMest.year) [1] 20.34141 52.21187 If I calculate the mean for 1975 (which corresponds to the first value in above vector -- 35.94605) using the ouput from popMeans(lmMod, c(SITE,COUNTYR_F)) above, I obtain 1530.253, which makes sense given my data. So why are the population marginal means for year (i.e., averaging across sites) so low in the vector immediately above? I'm obviously missing something crucial here...(and I know I'll feel like a dimwit when it hits me). Note that if I use popMeans to obtain the marginal mean across years for each site the output looks just fine: pM.site-popMeans(lmMod,SITE) LMest.site-exp(pM.site$Estimate) round(LMest.site,3) [1] 2.108 0.643 0.615 7.728 4.289 0.541 1.149 827.64529.054 322.30973.696 1.067 27116.44644.367 0.885 17.267 [17] 0.743 2529.955 114.254 5624.021 2.652 167.986 6181.059 32.175 0.728 0.685 0.590 6.184 2399.361 0.633 6943.247 0.902 [33] 0.740 3.934 0.83111.362 0.843 733.44218.123 1807.352 2361.726 2.260 0.650 226.013 1.037 3808.097 294.388 1.161 [49] 2.42816.572 3006.224 0.776 0.946 4587.31230.342 0.628 0.986 8.147 0.798 241.99540.880 466.779 395.398 0.688 [65]45.66834.119 529.253 0.61567.455 6.129 883.504 1487.803 2133.575 298.47231.981 907.871 0.982 1.271 3.636 9.387 [81] 110.531 1129.33031.332 2905.735 23512.16888.917 8666.546 7276.974 215.724 1740.38121.53029.327 1.388 mean(LMest.site) [1] 1319.349 My ultimate goal is to use the marginal means to impute the missing values; however, I'm concerned that I'm doing something wrong given the output for the marginal means for years (i.e., averaging across sites). Thanks in advance for any input. Cheers, Jenn - Original Message From: Andy Liaw andy_l...@merck.com To: Jenn Barrett jsbar...@sfu.ca, r-help@r-project.org Sent: Thursday, April 5, 2012 8:40:04 AM Subject: RE: [R] Imputing missing values using LSmeans (i.e., population marginal means) - advice in R? Don't know how you searched, but perhaps this might help: https://stat.ethz.ch/pipermail/r-help/2007-March/128064.html -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jenn Barrett Sent: Tuesday, April 03, 2012 1:23 AM To: r-help@r-project.org Subject: [R] Imputing missing values using LSmeans (i.e., population marginal means) - advice in R? Hi folks, I have a dataset that consists of counts over a ~30 year period at multiple (200) sites. Only one count is conducted at each site in each year; however, not all sites are surveyed in all years. I need to impute the missing values because I need an estimate of the total population size (i.e., sum of counts across all sites) in each year as input to another model. head(newdat,40) SITE YEAR COUNT 1 1 1975 12620 2 1 1976 13499 3 1 1977 45575 4 1 1978 21919 5 1 1979 33423 ... 372 1975 4 382 1978 40322 392 1979 7
Re: [R] summaryBy: transformed variable on RHS of formula?
Sorry, no - you will have to do something like the latter suggestion. Regards Søren -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Alexander Shenkin Sent: 2. april 2012 17:59 To: r-help@r-project.org Subject: [R] summaryBy: transformed variable on RHS of formula? Hi Folks, I'm trying to cut my data inside the summaryBy function. Perhaps formulas don't work that way? I'd like to avoid adding another column if possible, but if I have to, I have to. Any ideas? Thanks, Allie require(doBy) df = dataframe(a - rnorm(100), b -rnorm(100)) summaryBy(a ~ cut(b,c(-100,-1,1,100)), data=df) # preferred solution, but it throws an error # Error in `[.data.frame`(data, , rh.var, drop = FALSE) : undefined columns selected df$c = cut(b,c(-100,-1,1,100)) summaryBy(a ~ c, data=df) # works fine __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] expand.grid (the half!)
Something like this? x - expand.grid(c(1,2,3),c(1,2,3)) x[x[,2]=x[,1],] Var1 Var2 111 412 522 713 823 933 Regards Søren -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Alaios Sent: 24. marts 2012 16:09 To: R help Subject: [R] expand.grid (the half!) Dear all, I am using expand.grid for calculating all the possible values between four pairs. I would like to ask you if it is possible to filter the result out, so to keep all unique pairs. In my algorithm the input c(1,2) produces the same results as the c(2,1) so for example in the following code below expand.grid(c(1,2,3),c(1,2,3)) Var1 Var2 1 1 1 2 2 1 3 3 1 4 1 2 5 2 2 6 3 2 7 1 3 8 2 3 9 3 3 2,1 duplicates with 1,2 3,1 duplicates with 1,3 How I can removed these entries? The expand.grid function does not seem to have more arguments. Regards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fitting loglinear model with glm() and loglm()
Dear Christofer, loglm uses an iterative proportional scaling (IPS) algorithm for fitting a log-linear model to a contingency table. glm uses an iteratively reweighted least squares algorithm. The result from IPS is exact. Regards Søren -Oprindelig meddelelse- Fra: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] På vegne af Christofer Bogaso Sendt: 20. marts 2012 11:04 Til: r-help@r-project.org Emne: [R] Fitting loglinear model with glm() and loglm() Dear all, I have small difficulty in comprehending the loglinear model with R. Assume, we have following data dat - array(c(911, 44, 538, 456, 3, 2, 43, 279), c(2, 2, 2)) Now I fit a loglinear model with this and get the fitted values: library(MASS) Model_1 - loglm(~1 + 2 + 3, dat) fitted(Model_1) I could do this same task using glm() function as well because loglinear model is just 1 kind of glm ### Create dummy variables manually Dummy_Variable_Matrix - rbind(c(1, 1, 1), c(0, 1, 1), c(1, 0, 1), c(0, 0, 1), c(1, 1, 0), c(0, 1, 0), c(1, 0, 0), c(0, 0, 0)) ### Fit glm model_2 - glm(as.vector(dat) ~ Dummy_Variable_Matrix[,1] + Dummy_Variable_Matrix[,2] + Dummy_Variable_Matrix[,3], poisson(link = log)); fitted(model_2) ### However fitted(model_2) == as.vector(fitted(Model_1)) ### do not match However it is true that the difference is very small, still I am wondering whether should I just ingore that small difference? Or I have done something fundamentally wrong? Thanks for your help! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] gee: suppress printout
I don't think it can be removed, a message like this has been coming out for several years and there may be a good reason why it is there. Your best bet is probably to approach the package maintainer with a suggestion to alter the code. Regards Søren -Oprindelig meddelelse- Fra: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] På vegne af Ginata86 Sendt: 2. februar 2012 06:38 Til: r-help@r-project.org Emne: Re: [R] gee: suppress printout I am using the method to sink the output. However, it can only suppress 'user's initial regression estimate ' and still display the following sentence ' Beginning Cgee S-function, @(#) geeformula.q 4.13 98/01/27' I am just wondering is there any way that we can also suppress this one? Because I need to loop this for many times, it's annoying to display this one. -- View this message in context: http://r.789695.n4.nabble.com/gee-suppress-printout-tp908053p4350605.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. - Ingen virus fundet i denne meddelelse. Kontrolleret af AVG - www.avg.com Version: 2012.0.1913 / Virusdatabase: 2112/4780 - Udgivelsesdato: 01-02-2012 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Calling update on an lm-object inside a function
Dear all, I want to update an lm (or glm) object by changing the response variable and I want to do so inside a function. Doing the update outside of a function is straight forward: x - 1:5 y - c(1,2,3,3,6) mm - lm(y~x) y2 - c(1,3,3,4,6) mm2- update(mm, y2 ~ .) But I want to make the update inside a function (where the new response variable is declared inside the function). If I do foo - function(mod){ y3 - c(1,3,3,4,6) update(mod, y3 ~ .) } Then I get foo(mm) Error in eval(expr, envir, enclos) : object 'y3' not found (because y3 is not known in the global environment - I suppose). To fix this I do foo2 - function(mod){ y3 - c(1,3,3,4,6) mod2 - eval(getCall(mod)) update(mod2, y3 ~ .) } foo2(mm) Call: lm(formula = y3 ~ x) Coefficients: (Intercept)x 0.1 1.1 Question: Is this the appropriate way of making such a model available for an update inside a function, or is there a better way? I guess so - because: If I change the model formula of my model and then invoke foo2 I get mm3 - update(mm,.~.-x) foo2(mm3) Error in eval(expr, envir, enclos) : object 'y3' not found This puzzles me. Question: can anyone help me clarify why this happens and what I can do to fix it. Thanks in advance Søren __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Relationship between covariance and inverse covariance matrices
Your question is not all that R-related, but inverse covariance matrices with zero entries corresponds to conditional independence restrictions in the multivaritate normal distribution. Such inverse covariance matrices are key ingredients in graphical Gaussian models (also known as covariance selection models). You may want to study the litterature on such models. Regards Søren Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] P#229; vegne af Vivian Shih [v...@ucla.edu] Sendt: 8. december 2011 23:42 Til: r-help@r-project.org Emne: [R] Relationship between covariance and inverse covariance matrices Hi, I've been trying to figure out a special set of covariance matrices that causes some symmetric zero elements in the inverse covariance matrix but am having trouble figuring out if that is possible. Say, for example, matrix a is a 4x4 covariance matrix with equal variance and zero covariance elements, i.e. [,1] [,2] [,3] [,4] [1,]4000 [2,]0400 [3,]0040 [4,]0004 Now if we let a[1,2]=a[2,1]=3, then the inverse covariance matrix will have nonzero elements on the diagonals as well as for elements [1,2] and [2,1]. If we further let a[3,4]=a[4,3]=0.5 then the indices of the nonzero elements of the covariance matrix also matches those indices of the inverse. The problem is, if any of the nonzero off-diagonal indices match, then the inverse covariance matrix will have non-matching nonzero elements. For example, if a[1,2]=a[2,1]=3 as before but now we'll let a[2,3]=a[3,2]=0.5, then a would be: [,1] [,2] [,3] [,4] [1,]4 3.0 0.00 [2,]3 4.0 0.50 [3,]0 0.5 4.00 [4,]0 0.0 0.04 The inverse covariance matrix is now: [,1][,2][,3] [,4] [1,] 0.5833 -0. 0.0556 0.00 [2,] -0. 0.59259259 -0.07407407 0.00 [3,] 0.0556 -0.07407407 0.25925926 0.00 [4,] 0. 0. 0. 0.25 If we let a[1,2] and a[2,3] be nonzero, then the inverse will create a nonzero [1,3]. Does that happen all the time? I've tried to write out the algebraic system of linear equations for a and a-inverse but couldn't come up with anything. Let me know if I'm not clear on anything. Basically I'd just like to see what type of covariance matrices will produce an inverse covariance matrix with some zero elements. Thanks, Vivian __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How do I query ... in a function call?
You can do something like this: test - function(x,...){ print(x) args = list(...) if('y' %in% names(args))print(args$y) if('z' %in% names(args))print(args$z) } Regards Søren Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] P#229; vegne af Jonathan Greenberg [j...@illinois.edu] Sendt: 21. november 2011 23:18 Til: r-help Emne: [R] How do I query ... in a function call? This is probably a very noobish question, but if I want to create a function that allows an undetermined number of, say, numeric vectors to be fed to it, I would use: myfunction = function(...) { # Do something } Right? If so, how do I a) count the number of vectors fed to the function, and b) how do I treat those vectors as variables, e.g. for the call: myfunction(c(1:10),c(2:11),c(3:13)) Thanks! --j -- Jonathan A. Greenberg, PhD Assistant Professor Department of Geography University of Illinois at Urbana-Champaign 607 South Mathews Avenue, MC 150 Urbana, IL 61801 Phone: 415-763-5476 AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007 http://www.geog.illinois.edu/people/JonathanGreenberg.html [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] multicore combn
Just thought I'd let you know the following: In the gRbase package there is a function called combnPrim which does the same as combn but it is implemented in C - and is quite a bit faster than combn(). Regards Søren Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] P#229; vegne af jebyrnes [byr...@msi.ucsb.edu] Sendt: 16. oktober 2011 03:25 Til: r-help@r-project.org Emne: [R] multicore combn This is a 'rather than re-invent the wheel' post. Has anyone out there re-written combn so that it can be parallelized - with multicore, snow, or otherwise? I have a job that requires large numbers of combinations, and rather than get all of the index values, then crank it through mclapply, I was wondering if there was a way to just do this natively within a function. Just curious. Thanks! -Jarrett -- View this message in context: http://r.789695.n4.nabble.com/multicore-combn-tp3908633p3908633.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Package snow: is there any way to check if a cluster is acticve
Is there a 'proper' way of checking if cluster is active. For example, I create a cluster called .PBcluster str(.PBcluster) List of 4 $ :List of 3 ..$ con :Classes 'sockconn', 'connection' atomic [1:1] 3 .. .. ..- attr(*, conn_id)=externalptr ..$ host: chr localhost ..$ rank: int 1 ..- attr(*, class)= chr SOCKnode $ :List of 3 Then I stop it with stopCluster(.PBcluster) .PBcluster [[1]] $con Error in summary.connection(x) : invalid connection str(.PBcluster) List of 4 $ :List of 3 ..$ con :Classes 'sockconn', 'connection' atomic [1:1] 3 .. .. ..- attr(*, conn_id)=externalptr ..$ host: chr localhost ..$ rank: int 1 ..- attr(*, class)= chr SOCKnode - but is there a way in which I can check if the cluster is active?? Regards Søren __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Can't get installing a package source (.tar.gz) from a web page to work...
Thanks Uwe, The problem, however, is not solved. If I do: download.file(http://gbi.agrsci.dk/statistics/courses/2011-ISMLS-course/data/LiSciData_0.0-03.tar.gz;, tempdir()) Error in download.file(http://gbi.agrsci.dk/statistics/courses/2011-ISMLS-course/data/LiSciData_0.0-03.tar.gz;, : cannot open destfile 'c:\temp\RtmpcrQ0WM', reason 'Permission denied' However, if I specify a filename then things are working: download.file(http://gbi.agrsci.dk/statistics/courses/2011-ISMLS-course/data/LiSciData_0.0-03.tar.gz;, paste(tempdir(),thisfile,sep=\\)) trying URL 'http://gbi.agrsci.dk/statistics/courses/2011-ISMLS-course/data/LiSciData_0.0-03.tar.gz' Content type 'application/x-tar' length 315847 bytes (308 Kb) opened URL downloaded 308 Kb dir(tempdir()) [1] thisfile According to to the documentation: Destfile A character string with the name where the downloaded file is saved. Tilde-expansion is performed. I read the documentation such that I can specify a directory in which the file is to be put, but I may be wrong; or is it possible that there is a bug somewhere? Best regards Søren -Oprindelig meddelelse- Fra: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] Sendt: 15. september 2011 10:47 Til: Søren Højsgaard Cc: r-h...@stat.math.ethz.ch Emne: Re: [R] Can't get installing a package source (.tar.gz) from a web page to work... On 15.09.2011 10:34, Søren Højsgaard wrote: I have created an R-package with datasets which I want my students to install (the package is not on CRAN). 1) I've put the package on the web in a directory called 'data' and I thought I could do: install.packages(http://gbi.agrsci.dk/statistics/courses/2011-ISMLS-course/data/LiSciData_0.0-03.tar.gz,repos=NULL,type=source;) Warning: invalid package 'http://gbi.agrsci.dk/statistics/courses/2011-ISMLS-course/data/LiSciData_0.0-03.tar.gz' Error: ERROR: no packages specified Warning messages: 1: running command 'C:/programs/R/current/bin/i386/R CMD INSTALL -l C:/programs/R/current/library http://gbi.agrsci.dk/statistics/courses/2011-ISMLS-course/data/LiSciData_0.0-03.tar.gz;' had status 1 2: In install.packages(http://gbi.agrsci.dk/statistics/courses/2011-ISMLS-course/data/LiSciData_0.0-03.tar.gz;, : installation of package 'http://gbi.agrsci.dk/statistics/courses/2011-ISMLS-course/data/LiSciData_0.0-03.tar.gz' had non-zero exit status Right, install.packages assumes a package name or a file path. URLs (or any othr connections) are not supported. 2) I've then put the package in data/src/contrib/ and try: install.packages('LiSciData_0.0-03.tar.gz',repos='http://gbi.agrsci.dk/statistics/courses/2011-ISMLS-course/data/', type='source') Warning: unable to access index for repository http://gbi.agrsci.dk/statistics/courses/2011-ISMLS-course/data/src/contrib Warning message: In getDependencies(pkgs, dependencies, available, lib) : package 'LiSciData_0.0-03.tar.gz' is not available (for R version 2.13.1) If you want to use it as a repository, you have to make such a repository. For a source repository, create subdirs ./src/contrib and put your package there. Afterwards, you can run tools::write_PACKAGES on that directory in order to create PACKAGES and PACKAGES.gz files for that repository. 3) If I put the package in the Rs working directory then the following works: install.packages(LiSciData_0.0-03.tar.gz,repos=NULL,type=source) Right, hence you can also tell your students to: download.file(http://gbi.agrsci.dk/statistics/courses/2011-ISMLS-course/data/LiSciData_0.0-03.tar.gz;, tempdir()) install.packages(file.path(tempdir(), 'LiSciData_0.0-03.tar.gz'), repos=NULL, type='source') Best wishes, Uee I would much prefer if it could be done directly from the web in the spirit of attempt 1) above (because then fewer things can go wrong for the students). Any hint on what I am doing wrong? sessionInfo() shown below. Regards Søren sessionInfo() R version 2.13.1 (2011-07-08) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252 LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C LC_TIME=Danish_Denmark.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] SHDtools_1.0 loaded via a namespace (and not attached): [1] tools_2.13.1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self
[R] Can't get installing a package source (.tar.gz) from a web page to work...
I have created an R-package with datasets which I want my students to install (the package is not on CRAN). 1) I've put the package on the web in a directory called 'data' and I thought I could do: install.packages(http://gbi.agrsci.dk/statistics/courses/2011-ISMLS-course/data/LiSciData_0.0-03.tar.gz,repos=NULL,type=source;) Warning: invalid package 'http://gbi.agrsci.dk/statistics/courses/2011-ISMLS-course/data/LiSciData_0.0-03.tar.gz' Error: ERROR: no packages specified Warning messages: 1: running command 'C:/programs/R/current/bin/i386/R CMD INSTALL -l C:/programs/R/current/library http://gbi.agrsci.dk/statistics/courses/2011-ISMLS-course/data/LiSciData_0.0-03.tar.gz;' had status 1 2: In install.packages(http://gbi.agrsci.dk/statistics/courses/2011-ISMLS-course/data/LiSciData_0.0-03.tar.gz;, : installation of package 'http://gbi.agrsci.dk/statistics/courses/2011-ISMLS-course/data/LiSciData_0.0-03.tar.gz' had non-zero exit status 2) I've then put the package in data/src/contrib/ and try: install.packages('LiSciData_0.0-03.tar.gz',repos='http://gbi.agrsci.dk/statistics/courses/2011-ISMLS-course/data/', type='source') Warning: unable to access index for repository http://gbi.agrsci.dk/statistics/courses/2011-ISMLS-course/data/src/contrib Warning message: In getDependencies(pkgs, dependencies, available, lib) : package ‘LiSciData_0.0-03.tar.gz’ is not available (for R version 2.13.1) 3) If I put the package in the Rs working directory then the following works: install.packages(LiSciData_0.0-03.tar.gz,repos=NULL,type=source) I would much prefer if it could be done directly from the web in the spirit of attempt 1) above (because then fewer things can go wrong for the students). Any hint on what I am doing wrong? sessionInfo() shown below. Regards Søren sessionInfo() R version 2.13.1 (2011-07-08) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252 LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C LC_TIME=Danish_Denmark.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] SHDtools_1.0 loaded via a namespace (and not attached): [1] tools_2.13.1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] installing Rgraphviz
Hardly an R question, but a google search with the string change the path variable windows 7 gave quite a few hits, for example http://geekswithblogs.net/renso/archive/2009/10/21/how-to-set-the-windows-path-in-windows-7.aspx Regards Søren Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] P#229; vegne af Data Analytics Corp. [w...@dataanalyticscorp.com] Sendt: 21. juli 2011 05:31 Til: r-help@r-project.org Emne: [R] installing Rgraphviz Hi, I attempted to install Rgraphviz but ran into a problem. It requires graphviz 2.20.3. I have this and installed it but the Windows 7 system path variable has to be modified to include the path to the graphviz bin file. How do I do this on Windows 7? It's been a long time since I had to change the path variable. Thanks, Walt Walter R. Paczkowski, Ph.D. Data Analytics Corp. 44 Hamilton Lane Plainsboro, NJ 08536 (V) 609-936-8999 (F) 609-936-3733 w...@dataanalyticscorp.com www.dataanalyticscorp.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using stimulate(model) for parametric bootstrapping in lmer repeatabilities
Dear Jenni, In the newest version of the doBy package there is a function called PBrefdist (and PBrefdist.mer) for calculating the reference distribution of the likelihood ratio statistic for comparing nested models. Looking into this function may help you. Perhaps the functions PBmodcomp and BCmodcomp (and their .mer methods) for calculating p-values based on parametric bootstrap can also be of inspiration. Regards Søren Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] P#229; vegne af Jenni Sanderson [jennifer.louise.sander...@googlemail.com] Sendt: 8. juni 2011 09:56 Til: r-help@r-project.org; r-sig-mixed-mod...@r-project.org Emne: [R] using stimulate(model) for parametric bootstrapping in lmer repeatabilities Hi all, I am currently doing a consistency analysis using an lmer model and trying to use parametric bootstrapping for the confidence intervals. My model is like this: model-lmer(y~A+B+(1|C/D)+(1|E),binomial) where E is the individual level for consistency analysis, A-D are other fixed and random effects that I have to control for. Following Nakagawa and Scheilzeth I can work out the repeatability estimate using the following (as it is a binomial and the residual variance is fixed at 1). attr(lme4::VarCorr(model)$E, stddev)^2 / (1*(pi^2)/3 + attr(lme4::VarCorr(model)$E, stddev)^2 + attr(lme4::VarCorr(model)$C, stddev)^2 + attr(lme4::VarCorr(model)$D, stddev)^2 ) My question is can I use stimulate(model) to generate values that I can then use to do parametric bootstrap analysis and generate the confidence intervals? Something like this: n-length(A) niter-1000 y-matrix(nrow=n,ncol=niter*2) for (i in 1:niter) { y[,I(i*2-1):I(i*2)]-simulate(model)[,1] } rvalues-numeric() for (i in 1:niter) { yboot-cbind(y[,I(i*2-1)],y[,I(i*2)]) mboot-lmer(y~A+B+(1|C/D)+(1|E),binomial) rvalues[i]- attr(lme4::VarCorr(mboot)$E, stddev)^2/(1*(pi^2)/3 + attr(lme4::VarCorr(mboot)$E, stddev)^2 + attr(lme4::VarCorr(mboot)$C, stddev)^2 + attr(lme4::VarCorr(mboot)$D, stddev)^2 )} confidence.intervals-quantile(rvalues,c(0.05,0.95)) In the guide to lme4 it says that stimulate() generate simulations based on the estimated fitted models (conditional on the estimated values of both the random and fixed effects), which sounds like exactly what I would need to generate values for parametric bootstrapping but I can't find any examples of where anyone has done this. Any advice would be very much appreciated! Thank you very much. Jenni Jenni Sanderson PhD student - Conflict and Cooperation in Vertebrate Societies University of Exeter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problem with makeSOCKcluster depending on R patch version
That raises another question: Will that patched version (2011-05-13 r55886) be made available as a windows binary - and if so: when? Regards Søren Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] P#229; vegne af Uwe Ligges [lig...@statistik.tu-dortmund.de] Sendt: 14. maj 2011 18:23 Til: Ulrich Halekoh Cc: r-help@r-project.org Emne: Re: [R] problem with makeSOCKcluster depending on R patch version On 13.05.2011 14:01, Ulrich Halekoh wrote: Dear, I encountered a problem using the makeSOCKcluster function depending the patched version of R-2.13.0 I used. library(snow) cl- makeSOCKcluster(rep(localhost, 2)) this works fine for the R-13.0 patch (2011-04-28 r55678) but not for the patch R-13.0 patch (2011-05-10 r55826) If R-2.13.0 patched is meant: I do not see this with a recent snapshot (2011-05-13 r55886). Uwe Ligges In the latter case the command keeps running. Interrupting the command I get the error message Error in socketConnection(port = port, server = TRUE, blocking = TRUE, : cannot open the connection In addition: Warning message: In socketConnection(port = port, server = TRUE, blocking = TRUE, : problem in listening on this socket Does work R version 2.13.0 Patched (2011-04-28 r55678) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252 [3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C [5] LC_TIME=Danish_Denmark.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] snow_0.3-3 Does not work R version 2.13.0 Patched (2011-05-10 r55826) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252 [3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C [5] LC_TIME=Danish_Denmark.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] snow_0.3-3 Kind regards Ulrich Halekoh Associate Professor Aarhus University Email: ulrich.hale...@agrsci.dk __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problem with makeSOCKcluster depending on R patch version
I just downloaded the patched version from the Danish mirror; http://mirrors.dotsrc.org/cran/ That gave me: R version 2.13.0 Patched (2011-05-10 r55826) - which is *not* the version you refer to. Where may one get the latest patch then? Regards Søren Fra: Uwe Ligges [lig...@statistik.tu-dortmund.de] Sendt: 15. maj 2011 15:25 Til: Søren Højsgaard Cc: Ulrich Halekoh; r-help@r-project.org Emne: Re: SV: [R] problem with makeSOCKcluster depending on R patch version On 15.05.2011 12:27, Søren Højsgaard wrote: That raises another question: Will that patched version (2011-05-13 r55886) be made available as a windows binary - and if so: when? Daily builds for WIndows of R-patched are available from CRAN. Best, uwe Regards Søren Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] P#229; vegne af Uwe Ligges [lig...@statistik.tu-dortmund.de] Sendt: 14. maj 2011 18:23 Til: Ulrich Halekoh Cc: r-help@r-project.org Emne: Re: [R] problem with makeSOCKcluster depending on R patch version On 13.05.2011 14:01, Ulrich Halekoh wrote: Dear, I encountered a problem using the makeSOCKcluster function depending the patched version of R-2.13.0 I used. library(snow) cl- makeSOCKcluster(rep(localhost, 2)) this works fine for the R-13.0 patch (2011-04-28 r55678) but not for the patch R-13.0 patch (2011-05-10 r55826) If R-2.13.0 patched is meant: I do not see this with a recent snapshot (2011-05-13 r55886). Uwe Ligges In the latter case the command keeps running. Interrupting the command I get the error message Error in socketConnection(port = port, server = TRUE, blocking = TRUE, : cannot open the connection In addition: Warning message: In socketConnection(port = port, server = TRUE, blocking = TRUE, : problem in listening on this socket Does work R version 2.13.0 Patched (2011-04-28 r55678) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252 [3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C [5] LC_TIME=Danish_Denmark.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] snow_0.3-3 Does not work R version 2.13.0 Patched (2011-05-10 r55826) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252 [3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C [5] LC_TIME=Danish_Denmark.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] snow_0.3-3 Kind regards Ulrich Halekoh Associate Professor Aarhus University Email: ulrich.hale...@agrsci.dk __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problems with Rterm 2.13.0 - but not RGui
A safe way out of this mess is to install R somewhere else. For example, create a directory c:\Programs and install R there. Regards Søren -Oprindelig meddelelse- Fra: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] På vegne af Jonathan Daily Sendt: 3. maj 2011 13:59 Til: Stefan McKinnon Høj-Edwards Cc: r-help@r-project.org Emne: Re: [R] Problems with Rterm 2.13.0 - but not RGui Ah ok. I suppose the fix is to get the hard path (C:/Program Files/...) on the search path and remove the symlink from the search path. Does that work? 2011/5/3 Stefan McKinnon Høj-Edwards stefan.hoj-edwa...@agrsci.dk: Yes, the message is pretty clear, but it has nothing to do with running as admin. I have just tried to start a command line with admin privileges and the error still occurs. Regarding Rgui, I started it by opening the shortcut. Now I've tracked down the problem a bit, and the problem appears to be connected to which folder R is called from. And by sheer luck I've resolved the problem: In all previous versions of Windows, on the Danish editions, the C:\Program Files directory was called C:\Programmer. This appears to be the case in Windows 7, but C:\Programmer is a symbolic link (hard/soft?) to C:\Program Files. And apparently, I've been calling R from C:\Programmer instead of C:\Program Files which gave the problem. When/how/why I changed the PATH variable to the symbolic link is unclear, but a quick check reveals that the problem did not exist in R 2.12.1: C:\Programmer\R\R-2.12.1\bin\i386\Rterm # No problem C:\Programmer\R\R-2.13.0\bin\i386\Rterm # Problem I will submit a bug report on this. Kind regards, Stefan McKinnon Edwards -Oprindelig meddelelse- Fra: Jonathan Daily [mailto:biomathjda...@gmail.com] Sendt: 2. maj 2011 16:59 Til: Stefan McKinnon Høj-Edwards Cc: r-help@r-project.org Emne: Re: [R] Problems with Rterm 2.13.0 - but not RGui The message is pretty clear. Access denied means you don't have permission to access the path. This also explains why the packages fail to load - you don't have access to R's package library. It most likely works on RGui because you are clicking it/running it as admin (you did not specify how you ran RGui). 2011/5/2 Stefan McKinnon Høj-Edwards stefan.hoj-edwa...@agrsci.dk: Hi all, I have just installed R 2.13.0 and I am experiencing problems with the terminal, but not the with the GUI interface. I am Windows 7. When running R or Rterm from a commandline I receive the following: Warning message: In normalizePath(path.expand(path), winslash, mustWork) : path[3]=C:/Programmer/R/R-2.13.0/library: Adgang nægtet R version 2.13.0 (2011-04-13) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i386-pc-mingw32/i386 (32-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. Warning message: package methods in options(defaultPackages) was not found During startup - Warning messages: 1: package 'datasets' in options(defaultPackages) was not found 2: package 'utils' in options(defaultPackages) was not found 3: package 'grDevices' in options(defaultPackages) was not found 4: package 'graphics' in options(defaultPackages) was not found 5: package 'stats' in options(defaultPackages) was not found 6: package 'methods' in options(defaultPackages) was not found Notice: C:/Programmer/ is the Danish equivalent of C:/Program Files. The first error Adgang nægtet is directly translated to Access denied. Any suggestions as how to fix this? Kind regards, Stefan McKinnon Edwards __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- === Jon Daily Technician === #!/usr/bin/env outside # It's great, trust me. -- === Jon Daily Technician === #!/usr/bin/env outside # It's great, trust me. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Simulation from discrete uniform
?sample -Oprindelig meddelelse- Fra: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] På vegne af cassie jones Sendt: 8. april 2011 03:16 Til: r-help@r-project.org Emne: [R] Simulation from discrete uniform Dear all, I am trying to simulate from discrete uniform distribution. But I could not find any in-built code in R. Could anyone help me please? Thanks in advance for the time and help. Cassie [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Quasipoisson with geeglm
Dear Ivy, In gee there is no quasipossion, because gee is in a way already quasi. With GEE we do not fit a poisson glm, but use in the construction of the sandwich covariance matrix the variance function of the poisson family. In Gee always an 'overdispersion' is estimated. Regards Søren Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] P#229; vegne af JANSEN, Ivy [ivy.jan...@inbo.be] Sendt: 7. april 2011 13:32 Til: r-help@r-project.org Emne: [R] Quasipoisson with geeglm Dear all, I am trying to use the GEE methodology to fit a trend for the number of butterflies observed at several sites. In total, there are 66 sites, and 19 years for which observations might be available. However, only 326 observations are available (instead of 1254). For the time being, I ignore the large number of missing values, and the fact that GEE is only valid under MCAR. When I run the following code geeglm(SumOfButterflies ~ RES_YEAR, family = poisson, data = ManijurtNoNA, id = RES_ROTE_ID, corstr = ar1) I obtain normal output. Not surprisingly, overdispersion is present (Estimated Scale Parameters: [1] 185.8571), so changing to quasipoisson is needed. However, the code below geeglm(SumOfButterflies ~ RES_YEAR, family = quasipoisson, data = ManijurtNoNA, id = RES_ROTE_ID, corstr = ar1) produces the following error Error in geese.fit(xx, yy, id, offset, soffset, w, waves = waves, zsca, : variance invalid. Other correlation structures encounter the same problem. I also tried adding waves = RES_YEAR (although I am not sure how waves should be used correctly), but it does not change anything. Any suggestions what might be wrong? Regards, Ivy [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Assigning a class attribute to a list or vector slows [ down
Dear list, I've noticed that if a list or a vector is given a class (by class(x) - something) then the selection operator slows down - quite a bit. For example: lll - as.list(letters) system.time({for(ii in 1:20)lll[-(1:4)]}) user system elapsed 0.480.000.49 class(lll) - foo system.time({for(ii in 1:20)lll[-(1:4)]}) user system elapsed 2.570.002.58 vvv - 1:100 system.time({for(ii in 1:20)vvv[-(1:4)]}) user system elapsed 0.710.000.72 class(vvv) - foo system.time({for(ii in 1:20)vvv[-(1:4)]}) user system elapsed 2.850.002.87 I guess that what happens is that R looks for a [-method for for foo objects and when such a method is not found, a default [-method is called? Is that so? What should one do to avoid such a slowdown when wanting to select elements from a list or a vector with a class? Using unclass is one option: class(vvv) - foo system.time({for(ii in 1:20)unclass(vvv)[-(1:4)]}) user system elapsed 0.940.000.94 Are there better ways? Best regards Søren PS: I am using R.2.12.2 on windows 7. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Strange result from sort: sort(c(aa, ff)) gives ff aa with R.2.12.1 on windows 7
Not sure if I qualify as being knowledgeable, but... You write I recall that 'aa' used to sort at the end of the alphabet in Danish telephone books, so it seems the sort used on Windows thinks so too. See ?Comparison for some further details. What I don't understand is that someone resident in Denmark finds this strange Yes, I can confirm that aa resides at the end of the Danish alphabet (as an old way of writing the letter which in modern writing is å). But what should one then do if one wants aa to mean an a followed by another a and not aa (=å) when calling sort?? Regards Søren Højsgaard -Oprindelig meddelelse- Fra: Prof Brian Ripley [mailto:rip...@stats.ox.ac.uk] Sendt: 2. februar 2011 13:21 Til: Søren Højsgaard Cc: r-h...@stat.math.ethz.ch Emne: Re: [R] Strange result from sort: sort(c(aa, ff)) gives ff aa with R.2.12.1 on windows 7 'Strange' to have no response on this. Can a knowledgeable Danish writer please confirm that this is how the OSes are supposed to handle Danish collation? On Mon, 24 Jan 2011, Prof Brian Ripley wrote: On Mon, 24 Jan 2011, Søren Højsgaard wrote: Dear list, Please consider the following call of sort sort(c(a,f)) [1] a f sort(c(f,a)) [1] a f sort(c(aa,ff)) [1] ff aa sort(c(ff,aa)) [1] ff aa The last two results look strange to me. Is that a bug??? It seems that you and your OS disagree about Danish, and I'm in no position to know which is correct. But this is not an R issue: the sorting is done by OS services. The result seems to come from calls to order: order(c(a,f)) [1] 1 2 order(c(f,a)) [1] 2 1 order(c(aa,ff)) [1] 2 1 order(c(ff,aa)) [1] 1 2 I get the same results on R.2.12.1, R.2.11.1 and R.2.13.0 on Windows 7. However on Linux, I get the right answer (the answer I expected). From the help pages I get the impression that there might be an issue about locale, but I didn't understand the details. Can anyone tell me what goes on here, please I recall that 'aa' used to sort at the end of the alphabet in Danish telephone books, so it seems the sort used on Windows thinks so too. See ?Comparison for some further details. What I don't understand is that someone resident in Denmark finds this strange I get exactly the same in a Danish locale on Mac OS X, for example: sort(c(aa,ff)) [1] ff aa and also on my Linux box (Fedora 14 with LC_COLLATE=da_DK.utf8) sort(c(aa,ff)) [1] ff aa en_DK is not a Danish locale (in is English in Denmark). If you want an English sort, try an English locale for LC_COLLATE (there may well be several, hence 'an'). Regards Søren sessionInfo() R version 2.12.1 Patched (2010-12-27 r53883) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252 [3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C [5] LC_TIME=Danish_Denmark.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] SHDtools_1.0 sessionInfo() R version 2.12.1 (2010-12-16) Platform: i686-pc-linux-gnu (32-bit) locale: [1] LC_CTYPE=en_DK.utf8 LC_NUMERIC=C [3] LC_TIME=en_DK.utf8LC_COLLATE=en_DK.utf8 [5] LC_MONETARY=C LC_MESSAGES=en_DK.utf8 [7] LC_PAPER=en_DK.utf8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_DK.utf8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Strange result from sort: sort(c(aa, ff)) gives ff aa with R.2.12.1 on windows 7
Dear list, Please consider the following call of sort sort(c(a,f)) [1] a f sort(c(f,a)) [1] a f sort(c(aa,ff)) [1] ff aa sort(c(ff,aa)) [1] ff aa The last two results look strange to me. Is that a bug??? The result seems to come from calls to order: order(c(a,f)) [1] 1 2 order(c(f,a)) [1] 2 1 order(c(aa,ff)) [1] 2 1 order(c(ff,aa)) [1] 1 2 I get the same results on R.2.12.1, R.2.11.1 and R.2.13.0 on Windows 7. However on Linux, I get the right answer (the answer I expected). From the help pages I get the impression that there might be an issue about locale, but I didn't understand the details. Can anyone tell me what goes on here, please Regards Søren sessionInfo() R version 2.12.1 Patched (2010-12-27 r53883) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252 [3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C [5] LC_TIME=Danish_Denmark.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] SHDtools_1.0 sessionInfo() R version 2.12.1 (2010-12-16) Platform: i686-pc-linux-gnu (32-bit) locale: [1] LC_CTYPE=en_DK.utf8 LC_NUMERIC=C [3] LC_TIME=en_DK.utf8LC_COLLATE=en_DK.utf8 [5] LC_MONETARY=C LC_MESSAGES=en_DK.utf8 [7] LC_PAPER=en_DK.utf8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_DK.utf8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using summaryBy with weighted data
It is currently not possible to pass weights in summaryBy. Regards Søren Fra: Joshua Wiley [jwiley.ps...@gmail.com] Sendt: 17. januar 2011 08:16 Til: Solomon Messing Cc: r-help@r-project.org; Søren Højsgaard Emne: Re: [R] Using summaryBy with weighted data Dear Solomon, On Sun, Jan 16, 2011 at 10:27 PM, Solomon Messing solomon.mess...@gmail.com wrote: Dear Soren and R users: I am trying to use the summaryBy function with weights. Is this possible? An example that illustrates what I am trying to do follows: library(doBy) ## make up some data response = rnorm(100) group = c(rep(1,20), rep(2,20), rep(3,20), rep(4,20), rep(5,20)) weights = runif(100, 0, 1) mydata = data.frame(response,group,weights) ## run summaryBy without weights: summaryBy(response~group, data = mydata, FUN = mean) ## attempt to run summaryBy with weights, throws error summaryBy(x~group, data = mydata, FUN = weighted.mean, w=weights ) ## throws the error: # Error in tapply(lh.data[, lh.var[vv]], rh.string.factor, function(x) { : # arguments must have same length My guess is that summaryBy is not giving weighted.mean() each group of weights, but instead is passing all of the weights in the data set each time it calls weighted.mean(). Yes, of course. It has no way of knowing that the weights should also be being broken down by groupthey are not in the formula. Do you know if there is some way to get summaryBy to pass weights to weighted.mean() only for each group? Ideally there would be a way to pass more than one variable to a function (e.g., response and weights) or just an entire object (mydata) broken down by group. Then you would just make a wrapper function to pass the right values to the x and w arguments of weighted.mean. Instead here is a somewhat hacked version: library(doBy) ## make up some data (easier) mydata - data.frame(response = rnorm(100), group = rep(1:5, each = 20), weights = runif(100, 0, 1)) ## manually compute weighted mean tmp - summaryBy(response*weights ~ group, data = mydata, FUN = sum) tmp[,2] - tmp[,2]/with(mydata, tapply(weights, group, sum)) tmp ## weighted means ## here's the 'problem', if you will, even with +, they are passed one at a time summaryBy(response + weights ~ group, data = mydata, FUN = str) summaryBy(mydata ~ group, data = mydata, FUN = str) ## here is an option using by(): xy - by(mydata, mydata$group, function(z) weighted.mean(z$response, z$weights)) xy ## if you don't like the formatting data.frame(group = names(c(xy)), weighted.mean = c(xy)) HTH, Josh I suspect this functionality would be a tremendous benefit to R users who regularly work with weighted data, such as myself. Thanks, Solomon Messing www.stanford.edu/~messing PS I know this basic example can be done using lapply(split(...)) approach referenced here: http://www.mail-archive.com/r-help@stat.math.ethz.ch/msg12349.html but for more complex tasks the lapply approach will mean writing a lot of extra code to run everything and then to get things formatted as nicely as summaryBy() was designed to do. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Changing a logical matrix into a numeric matrix
Just multiply by 1: m - matrix(c(T,T,F,T),nr=2) m [,1] [,2] [1,] TRUE FALSE [2,] TRUE TRUE m*1 [,1] [,2] [1,]10 [2,]11 -Oprindelig meddelelse- Fra: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] På vegne af emj83 Sendt: 10. januar 2011 10:17 Til: r-help@r-project.org Emne: [R] Changing a logical matrix into a numeric matrix Hi, I would like to turn my TRUE/FALSE matrix into a 1/0 matrix (i.e. True=1 and False=0) [,1] [,2] [,3] [1,] TRUE FALSE FALSE [2,] TRUE TRUE FALSE [3,] TRUE TRUE TRUE [,1] [,2] [,3] [1,]10 0 [2,]11 0 [3,]11 1 Is there a quick way of doing this without a loop? Thanks Emma -- View this message in context: http://r.789695.n4.nabble.com/Changing-a-logical-matrix-into-a-numeric-matrix-tp3206797p3206797.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Bayesian Belief Networks
Probability propragation is provided in the gRain package. Regards Søren Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] P#229; vegne af Michael Bedward [michael.bedw...@gmail.com] Sendt: 24. december 2010 00:01 Til: Data AnalyticsCorp. Cc: r-help@r-project.org Emne: Re: [R] Bayesian Belief Networks Hello Walt, Have a look at the bnlearn and deal packages. Michael On 24 December 2010 01:29, Data Analytics Corp. w...@dataanalyticscorp.com wrote: Hi, Does anyone know of a package for or any implementation of a Bayesian Belief Network in R? Thanks, Walt Walter R. Paczkowski, Ph.D. Data Analytics Corp. 44 Hamilton Lane Plainsboro, NJ 08536 (V) 609-936-8999 (F) 609-936-3733 w...@dataanalyticscorp.com www.dataanalyticscorp.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Sweave: Setting options with SweaveOpts{} when using driver=RweaveHTML
When using Sweave in connection with the driver RweaveLatex(), global options can be set with \SweaveOpts{}, e.g. \SweaveOpts{keep.source=T}. Does anybody know if it is possible to set global options in the same way when using Sweave with the driver RweaveHTML(). Regards Søren [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Calling substitute(expr, list(a=1)) when expr - expression(a+b+c)
# The result I am after is the result after a substitution in an expression, such as substitute(expression(a+b+c), list(a=1)) expression(1 + b + c) # However, the way I want to do it is for a an expression stored as a variable as (expr - expression(a+b+c)) expression(a + b + c) # a) The following does not work (expr2 - substitute(expr, list(a=1))) expr # b) - whereas this does work: ans - eval(substitute(substitute(qqq, list(a=1)), list(qqq=expr[[1]]))) as.expression(ans) expression(1 + b + c) # I have - at least - two problems: # I am not sure I understand 1) why a) does not work and 2) why b) does work. # Can anyone point me in the right direction? # Thanks # Søren [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Calling substitute(expr, list(a=1)) when expr - expression(a+b+c)
Thanks, but I think there is a small mistake in your code: expr - expression(a+b+c) do.call(substitute, list(expr, list(a=1))) expression(a + b + c) I think it should be: as.expression(do.call(substitute, list(expr[[1]], list(a=1 expression(1 + b + c) - or maybe it can be done in a simpler way? Regards Søren -Oprindelig meddelelse- Fra: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Sendt: 26. november 2010 14:39 Til: Søren Højsgaard Cc: r-h...@stat.math.ethz.ch Emne: Re: [R] Calling substitute(expr, list(a=1)) when expr - expression(a+b+c) On Fri, Nov 26, 2010 at 8:31 AM, Søren Højsgaard soren.hojsga...@agrsci.dk wrote: # The result I am after is the result after a substitution in an expression, such as substitute(expression(a+b+c), list(a=1)) expression(1 + b + c) # However, the way I want to do it is for a an expression stored as a variable as (expr - expression(a+b+c)) expression(a + b + c) # a) The following does not work (expr2 - substitute(expr, list(a=1))) expr # b) - whereas this does work: ans - eval(substitute(substitute(qqq, list(a=1)), list(qqq=expr[[1]]))) as.expression(ans) expression(1 + b + c) # I have - at least - two problems: # I am not sure I understand 1) why a) does not work and 2) why b) does work. # Can anyone point me in the right direction? It does not evaluate its argument so if expr is the first argument about the only thing you can substitute is expr itself: substitute(expr, list(expr = 3)) [1] 3 Try this: expr - expression(a+b+c) do.call(substitute, list(expr, list(a=1))) expression(a + b + c) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] odfWeave - Format error discovered in the file in sub-document content.xml at 2, 4047 (row, col)
When using odfWeave on an OpenOffice input document, I can not open the output document. I get the message Format error discovered in the file in sub-document content.xml at 2,4047 (row,col) Can anyone help me on this? (Apologies if this has been discussed before; I have not been able to find any info...) Info: I am using R.2.12.0 on Windows 7 (64 bit). I have downloaded the XML package from http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.12/ and I have compiled odfWeave myself Best regards Søren [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] odfWeave - Format error discovered in the file in sub-document content.xml at 2, 4047 (row, col)
Dear Mike, Good point - thanks. The lines that caused the error mentioned above are simply: = x - 1:10 x @ I could add that the document 'simple.odt' (which comes with odfWeave) causes the same error - but at row=109, col=1577 sessionInfo() R version 2.12.0 (2010-10-15) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252 LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C LC_TIME=Danish_Denmark.1252 attached base packages: [1] grid stats graphics grDevices utils datasets methods base other attached packages: [1] MASS_7.3-8 odfWeave_0.7.14 XML_3.2-0.1 lattice_0.19-13 loaded via a namespace (and not attached): [1] tools_2.12.0 Regards Søren -Oprindelig meddelelse- Fra: Mike Marchywka [mailto:marchy...@hotmail.com] Sendt: 16. november 2010 12:56 Til: Søren Højsgaard; r-h...@stat.math.ethz.ch Emne: RE: [R] odfWeave - Format error discovered in the file in sub-document content.xml at 2, 4047 (row, col) From: soren.hojsga...@agrsci.dk To: r-h...@stat.math.ethz.ch Date: Tue, 16 Nov 2010 11:32:06 +0100 Subject: [R] odfWeave - Format error discovered in the file in sub-document content.xml at 2, 4047 (row, col) When using odfWeave on an OpenOffice input document, I can not open the output document. I get the message Format error discovered in the file in sub-document content.xml at 2,4047 (row,col) Can anyone help me on this? (Apologies if this has been discussed before; I have not been able to find any info...) well, if it really means line 2 you could post the first few lines. Did you expect a line with 4047 columns? Info: I am using R.2.12.0 on Windows 7 (64 bit). I have downloaded the XML package from http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.12/ and I have compiled odfWeave myself Best regards Søren [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to view the top 20 lines in a long dataset
See ?head Regards Søren Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] P#229; vegne af Louis Plough [lplo...@usc.edu] Sendt: 1. november 2010 20:40 Til: r-help@r-project.org Emne: [R] how to view the top 20 lines in a long dataset Hi, I am simply looking for the function that will allow you to look at the top 20 lines of a long dataset? LP On Mon, Nov 1, 2010 at 10:46 AM, Louis Plough lplo...@usc.edu wrote: Hi, I am trying to generate all possible permutations (choose 2) of a vector, b, for example--using 'combn' the combinations in only one direction are generated... b-c(.1,.2,.3) combn(b,2) [,1] [,2] [,3] [1,] 0.1 0.1 0.2 [2,] 0.2 0.3 0.3 [1,] 0.1 0.2 0.3 0.2 0.3 0.3These should also be there. [2,] 0.1 0.2 0.3 0.1 0.1 0.2 Is there another R function that can do this?? Thanks, Louis [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] GEE with user-specified link function
For geepack there are no facilities for user defined link functions. Regards Søren Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] P#229; vegne af Kun Liu [victo...@hotmail.co.uk] Sendt: 12. oktober 2010 11:50 Til: r-help@r-project.org Emne: [R] GEE with user-specified link function Hello, I would like to try to fit a GEE with user-specified link function. I read through a couple of thread on the list, for example http://tolstoy.newcastle.edu.au/R/help/04/12/9768.html#start and http://tolstoy.newcastle.edu.au/R/help/06/04/25298.html. I noticed that they are all 6 or more years old and the answer is very clear for GLM, however for GEE I am still not sure. There are two existing package for GEE. One is called gee and anther is called geepack. However, in both package, they do not seem to involve the option of using user-defined link function. Could anyone help me with this please? Thanks very much indeed for any help. Best regards, Yours Sincerely, Victor PhD in Statistics The University of Manchester, UK [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Extracting elements from list: Is [[ always faster than $ ??
Dear list It seems to me that extracting elements from a list using '[[' is somewhat faster than using '$'. For example: x- as.list(1:25) names(x) - letters[1:length(x)] dput(x) structure(list(a = 1L, b = 2L, c = 3L, d = 4L, e = 5L, f = 6L, g = 7L, h = 8L, i = 9L, j = 10L, k = 11L, l = 12L, m = 13L, n = 14L, o = 15L, p = 16L, q = 17L, r = 18L, s = 19L, t = 20L, u = 21L, v = 22L, w = 23L, x = 24L, y = 25L), .Names = c(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y)) system.time({ for (ii in 1:100) x[[21]] }) user system elapsed 0.550.000.54 system.time({ for (ii in 1:100) x[[u]]}) user system elapsed 0.840.000.84 system.time({ for (ii in 1:100) x$u}) user system elapsed 1.120.001.13 Does anyone know if this is always the case? (I have not found anything about speed in this connection on the help pages, apologies if I have overlooked something). I use R.2.11.1 on Windows 7. Regards __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] transformation of data.frame
Like this? library(doBy) (ddd - read.table(foo.txt,header=T)) ID gen 1 42787 gen2 2 16070 gen2 3 16070 gen3 4 7409 Gen1 5 7409 gen3 6 6511 gen2 7 6417 gen3 8 16070 gen4 9 6511 gen4 aa-lapplyBy(~ID, data=ddd, + FUN=function(uu){ + list(uu$ID[1], paste(uu$gen, collapse=:)) + }) do.call(rbind,aa) [,1] [,2] 42787 42787 gen2 16070 16070 gen2:gen3:gen4 7409 7409 Gen1:gen3 6511 6511 gen2:gen4 6417 6417 gen3 Regards Søren -Oprindelig meddelelse- Fra: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] På vegne af Assa Yeroslaviz Sendt: 8. juli 2010 10:45 Til: r-h...@stat.math.ethz.ch Emne: [R] transformation of data.frame Hello all R users, I have a problems transforming (or maybe better regrouping) a data.frame. I have a big data.frame, which I would like to sum up according to a specific column. This is an example of my matrix: IDgen 0042787gen2 0016070gen2 0016070gen3 0007409Gen1 0007409gen3 0006511gen2 0006417gen3 0016070gen4 0006511gen4 I want to rearrange the matrix according to column GO, so that it will look likes that: GO:0042787 gen2 GO:0016070gen2 : gen3 : gen4 GO:0007409gen1 : gen3 GO:0006511gen2 : gen4 GO:0006417gen3 I've tried it with the package doBy (lapplyBy and paste) but it just doesn't work out. I will be very happy for any suggestions you might have to help me. Thanks Assa [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Generalised Estimating Equations on approx normal outcome with limited range
Hi, 1) There is no feature in geeglm for that sort of truncation of the outcome. 2) It is generally fragile - and not recommendable - to use corstr=unstructured in geeglm. Regards Søren Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] P#229; vegne af J D [jdprojects3...@gmail.com] Sendt: 22. juni 2010 16:30 Til: r-help@r-project.org Emne: [R] Generalised Estimating Equations on approx normal outcome with limited range Dear R users I am analysing data from a group of twins and their siblings. The measures that we are interested in are all correlated within families, with the correlations being stronger between twins than between non-twin siblings. The measures are all calculated from survey answers and by definition have limited ranges (e.g. -5 to +5), though within the range they are approximately normally distributed (with ~50 levels). One aim of the analysis is to assess whether the measures are related to certain covariates, and I have tried the generalised estimating equation function geeglm (library geepack) with the 'gaussian' family details like so: geeout - geeglm(outcome ~ covariate1 + covariate2, id=familyID, family=gaussian, data=dat, corstr=unstructured) But I'm thinking that the limited range of the outcome violates the assumption of normality and that the results could be off. Q: Is there a way in R, either in geeglm or another appropriate function, to take the limited range of the outcome into account? Another aim of the analysis is to combine the data from all members of all families to make percentile norms or standards for future comparisons. I don't want to use a poorly fitting model for this purpose especially, but in the hope that I will be able to account for the limited range somehow, I tried using geeglm to calculate a new mean and variance, adjusted for within-family correlation but without any adjustments for covariates. Q: It looks like it works but have I specified it correctly to get the statistics that I want? geeout - geeglm(outcome ~ 1, id=familyID, family=gaussian, data=dat, corstr=unstructured) # Then the adjusted mean would be in: summary(geeout)$geese$mean # and the adjusted variance would be the estimate in: summary(geeout)$geese$scale If you know of a better way to analyse this data, I would love to know this as well. Thank you very much for your time and any help you can offer. Jillian Dwyer [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] More efficient alternative to combn()?
Perhaps slightly off topic but there is a faster alternative to combn() called combnPrim() in the gRbase package: library(gRbase) system.time({for (ii in 1:1) combn(1:6,3)}) user system elapsed 4.020.004.02 system.time({for (ii in 1:1) combnPrim(1:6,3)}) user system elapsed 0.280.000.28 Notice that combnPrim() does not take the FUN argument but can easily be extended to do so. regards Søren Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] P#229; vegne af Charles C. Berry [cbe...@tajo.ucsd.edu] Sendt: 26. marts 2010 18:26 Til: elgorgonzola Cc: r-help@r-project.org Emne: Re: [R] More efficient alternative to combn()? On Fri, 26 Mar 2010, elgorgonzola wrote: Hi, i am working on a problem where i need to compute the products of all possible combinations of size m of the elements of a vector. I know that this can be achieved using the function combn(), e.g.: vector - 1:6 combn(x = vector, m = 3, FUN = function(y) prod(y)) In my case the vector has 2000 elements and i need to compute the values specified above for m = 32. Using combn() i encounter problems for m = 4. Is there any alternative to combn() that works more efficiently? Also my vector contains many duplicates, so there are actually only about 300 distinct values in the vector. This reduces the number of possible combinations significantly. Is there any way to use this fact to reduce the computational cost? It doesn't matter what the computational cost is. Even if the problem was just to enumerate the choose(300,32) products of unique elements you would need more than 10^33 Gigabytes of memory to store the result. Unless there is a lot more structure in your problem than you have described or unless some form of approximation is acceptable, it is not a problem you can hope to solve. HTH, Chuck Thanks in advance, El -- View this message in context: http://n4.nabble.com/More-efficient-alternative-to-combn-tp1692117p1692117.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating named lists
Rune, I doubt that this is possible because R-objects will typically not know their own name. Med venlig hilsen / Regards Søren Højsgaard -Oprindelig meddelelse- Fra: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] På vegne af Rune Schjellerup Philosof Sendt: 12. marts 2010 10:46 Til: Linlin Yan Cc: r-help@r-project.org Emne: Re: [R] Creating named lists No, I mean this: a - 1 b - 2 list(a=a, b=b) I just find it anoying, that I have to type the names of the variables twice. I would like something like this instead: list(a, b, use.var.names=TRUE) -- Rune Linlin Yan wrote: Did you mean this: n - c('a', 'b') structure(list(1, 2), names = n) $a [1] 1 $b [1] 2 On Fri, Mar 12, 2010 at 5:28 PM, Rune Schjellerup Philosof rphilo...@health.sdu.dk wrote: I often find myself making lists similar to this list(var1=var1, var2=var2) It doesn't seem list has an option, to make it use the name of the variable as name in the list. Is there another function that does this? -- Med venlig hilsen Rune Schjellerup Philosof Ph.d-stipendiat, Forskningsenheden for Biostatistik Telefon: 6550 3607 E-mail: rphilo...@health.sdu.dk Adresse: J.B. Winsløwsvej 9, 5000 Odense C SYDDANSK UNIVERSITET ___ * Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Med venlig hilsen Rune Schjellerup Philosof Ph.d-stipendiat, Forskningsenheden for Biostatistik Telefon: 6550 3607 E-mail: rphilo...@health.sdu.dk Adresse: J.B. Winsløwsvej 9, 5000 Odense C SYDDANSK UNIVERSITET ___ * Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] identical() mystery
It might have to do with the storage.mode(): reference - c(11, 14, 16, 5, 4, 2, 0, 15, 9, 0) storage.mode(reference) [1] double cpgDensity - as.integer(reference) storage.mode(cpgDensity) [1] integer identical(reference,cpgDensity) [1] FALSE regards Søren Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] P#229; vegne af Dario Strbenac [d.strbe...@garvan.org.au] Sendt: 1. marts 2010 07:24 Til: r-help@r-project.org Emne: [R] identical() mystery Hello, I have 2 vectors of the same mode and the same contents but I still get FALSE. Any ideas ? reference - c(11, 14, 16, 5, 4, 2, 0, 15, 9, 0) reference [1] 11 14 16 5 4 2 0 15 9 0 cpgDensity [1] 11 14 16 5 4 2 0 15 9 0 identical(cpgDensity, reference) [1] FALSE mode(cpgDensity) [1] numeric mode(reference) [1] numeric cpgDensity == reference [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE Thanyou, Dario. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] summary statistics for grouped data
You might find the summaryBy function in the doBy package useful. Regards Søren Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] P#229; vegne af jose romero [jlauren...@yahoo.com] Sendt: 12. februar 2010 18:23 Til: r-help@r-project.org Emne: [R] summary statistics for grouped data Hello list: Is there an easy way (preferably through one of the standard R packages) of obtaining summary statistics for grouped data? I could split the data into classes by hist, and then progressively calculate all the columns i need to obtain the mean and standard deviation, but i was looking for a single function that could do that with a data vector. Thanks in advance, jose romero [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R very large files
The sqldf package may be of help to you. Regards Søren -Oprindelig meddelelse- Fra: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] På vegne af Albert-Jan Roskam Sendt: 16. december 2009 11:59 Til: r-help@r-project.org Emne: [R] R very large files Hi, I very recently started using R (as in: last week) and I was wondering if anyone could point me to website(s) with sample code to deal with large datasets (length- and/or breadthwise). I understood that R was never designed to work with datasets larger than, say, a couple of hundred Mb. One way is (as I also read) to let R work in conjunction with SQL. That's one interesting approach I'd like to know more about. But I was also hoping that there also were pure R solutions for working with very large tables (was 'scan' designed for that?). In any case, a standard approach would be desirable. Thanks in advance. Cheers!! Albert-Jan ~~ In the face of ambiguity, refuse the temptation to guess. ~~ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] different fits for geese and geeglm in geepack?
It looks strange. If you send me data for a small reproducible example then I'll look into the issue. Regards Søren Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] P#229; vegne af Achaz von Hardenberg [achaz.hardenb...@gmail.com] Sendt: 26. november 2009 17:17 Til: r-help@r-project.org Emne: [R] different fits for geese and geeglm in geepack? Dear all, I am trying to fit a GEE model on eagle productivity (number of hatched offspring per nest) using the geeglm function in the library geepack and I found an odd result. My understanding is that the function geese and geeglm should give the same fits, as actually geeglm uses geese to fit the model, providing a glm style output. However, if I fit the same model with geeglm and geese I get slightly different estimates of the parameters. Most striking is the difference between the estimates of the correlation parameter where the differences are huge: (geese: alpha= -0.0727, se= 0.0608; geeglm: -0.219, se= 0.091). Anybody knows why this is like that and which of the two I should rather trust? (I attach the outputs of the two models at the end of this mail) thanks a lot for your hints! Achaz von Hardenberg PS: One more question actually: anybody has got some code to calculate the QICu values to compare GEE models with and without specific fixed factors using geepack? ## GEESE OUTPUT: Call: geese(formula = PROD ~ as.factor(clas3) + Twinter + Tprecova, id = Nterr, waves = anno, data = aquile.dat2, family = poisson, corstr = ar1) Mean Model: Mean Link: log Variance to Mean Relation: poisson Coefficients: estimate san.se waldp (Intercept)-1.7850 0.3661 23.77 1.08e-06 as.factor(clas3)2 0.7165 0.2475 8.38 3.79e-03 as.factor(clas3)3 0.5052 0.3368 2.25 1.34e-01 Twinter-0.1066 0.0464 5.28 2.16e-02 Tprecova -0.0549 0.0368 2.22 1.36e-01 Scale Model: Scale Link:identity Estimated Scale Parameters: estimate san.se waldp (Intercept)0.764 0.123 38.6 5.17e-10 Correlation Model: Correlation Structure: ar1 Correlation Link: identity Estimated Correlation Parameters: estimate san.se wald p alpha -0.0727 0.0608 1.43 0.232 Returned Error Value:0 Number of clusters: 21 Maximum cluster size: 20 ### GEEGLM OUTPUT: Call: geeglm(formula = PROD ~ as.factor(clas3) + Twinter + Tprecova, family = poisson, data = aquile.dat2, id = Nterr, waves = anno, corstr = ar1) Coefficients: Estimate Std.err Wald Pr(|W|) (Intercept)-1.7992 0.3751 23.01 1.6e-06 *** as.factor(clas3)2 0.7412 0.2623 7.99 0.0047 ** as.factor(clas3)3 0.5253 0.3335 2.48 0.1152 Twinter-0.1083 0.0473 5.24 0.0220 * Tprecova -0.0483 0.0354 1.86 0.1721 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Estimated Scale Parameters: Estimate Std.err (Intercept)0.773 0.117 Correlation: Structure = ar1 Link = identity Estimated Correlation Parameters: Estimate Std.err alpha -0.219 0.091 Number of clusters: 21 Maximum cluster size: 20 Dr. Achaz von Hardenberg Centro Studi Fauna Alpina - Alpine Wildlife Research Centre Servizio Sanitario e della Ricerca Scientifica Parco Nazionale Gran Paradiso, Degioz, 11, 11010-Valsavarenche (Ao), Italy Present address: National Centre for Statistical Ecology School of Mathematics, Statistics and Actuarial Science, University of Kent, Canterbury, UK E-mail: achaz.hardenb...@pngp.it fa...@pngp.it Skype: achazhardenberg Mobile: +44.(0)783.266.5995 Dr. Achaz von Hardenberg Centro Studi Fauna Alpina - Alpine Wildlife Research Centre Servizio Sanitario e della Ricerca Scientifica Parco Nazionale Gran Paradiso, Degioz, 11, 11010-Valsavarenche (Ao), Italy Present address: National Centre for Statistical Ecology School of Mathematics, Statistics and Actuarial Science, University of Kent, Canterbury, UK E-mail: achaz.hardenb...@pngp.it fa...@pngp.it Skype: achazhardenberg Mobile: +44.(0)783.266.5995 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Define lm/glm object without evaluating them
For e.g. lm/glm type models I would like to separate model specification and model fitting and then only fit the models later 'when data arrives'. To be specific, I would like make a specification like m1 - lm(rate~conc) m2 - lm(rate~I(conc^2)) and then later I want to 'put data into' the objects and evaluate (fit the model), e.g. something like update(m1, data=Puromycin) update(m2, data=Puromycin) The 'closest' I can get to what I want is 1) Specification: m.list -expression(lm(rate~conc), lm(rate~I(conc^2))) 2) Update with data: m.list2 - lapply(m.list, function(m) {m$data=Puromycin; return(m)}) 3) Now, evaluate: lapply(m.list2, eval) Can anyone point me to a simpler approach? Regards Søren __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Defining S3-methods for S4-objects: cannot coerce type 'S4' to vector of type 'integer'
In the 'doBy' package there is an esticon() function for calculating linear contrasts for various model types. I have defined an S3-method 'esticon.mer()' for 'mer' objects from the lme4 package. Building the package and invoking the method gives: esticon(fm1, c(1,1)) Confidence interval ( WALD ) level = 0.95 Error in as.integer(x) : cannot coerce type 'S4' to vector of type 'integer' However, if is source the source code into R then I get what I expected: esticon(fm1, c(1,1)) Confidence interval ( WALD ) level = 0.95 beta0 Estimate Std.Error X2.value DF Pr(|X^2|) Lower.CI Upper.CI 1 0 261.8724 6.786701 1488.888 1 0 248.5707 275.1741 The problem above arises because esticon.mer() uses the variance-covariance matrix of the fixed effects (vcv below) in a calculation (cm is a matrix): cm %*% vcv %*% t(cm). The result is: 1 x 1 Matrix of class dgeMatrix [,1] [1,] 46.05931 - and taking diag() of that matrix causes the error above... However, things work fine if I use as.matrix() as is: diag(as.matrix(cm %*% vcv %*% t(cm))). - This tentatively suggests that there is no diag() method for 'dgeMatrix' objects (can hardly be the case!), but why then does my code work when it is sourced into R??? - Does anyone have an idea about what goes wrong? ) - Is there anything 'special' that one must do in connection with defining S3-methods for S4 objects (e.g. in connection with package building)?? I use R 2.9.2 on windows XP. I am sure that such issues must have come up for others in the past but I've been unable to find questions/answers in the archives. Sorry if the topic has already been covered. Regards Søren Højsgaard [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] array slice notation?
Hi, 1) I think vector subscripting is faster than the solution below. 2) I don't understand the question, but it may be an idea to look at ?tableSlice and ?tableMargin in the gRbase package. Regards Søren Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] P#229; vegne af Steve Jaffe [sja...@riskspan.com] Sendt: 5. august 2009 04:45 Til: r-help@r-project.org Emne: Re: [R] array slice notation? Very nice. Two questions: 1 Do you have any idea of the timing difference, if any, between this and the vector-subscripting method? 2 How do you generalize this to select multiple rows eg with indexes given by a vector 'v'? Søren Højsgaard wrote: You can do A - HairEyeColor do.call([, c(list(A),list(1,T,T))) Sex Eye Male Female Brown 32 36 Blue11 9 Hazel 10 5 Green3 2 Regards Søren -- View this message in context: http://www.nabble.com/array-slice-notation--tp24814643p24819883.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] array slice notation?
You can do A - HairEyeColor do.call([, c(list(A),list(1,T,T))) Sex Eye Male Female Brown 32 36 Blue11 9 Hazel 10 5 Green3 2 Regards Søren Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] P#229; vegne af Steve Jaffe [sja...@riskspan.com] Sendt: 4. august 2009 21:23 Til: r-help@r-project.org Emne: [R] array slice notation? Suppose I have an n-diml array A and I want to extract the first row -- ie all elements A[1, ...] Interactively if I know 'n' I can write A[1,] with (n-1) commas. How do I do the same more generally, eg in a script? (I can think of doing this by converting A to a vector then extracting the approp elements then reshaping it to an array, but I wonder if there isn't a more straightforward approach) Thanks -- View this message in context: http://www.nabble.com/array-slice-notation--tp24814643p24814643.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to comment in R
You CAN NOT use /* and */ for begin/end comment in R. But if you choose Options - Main - Application in Tinn-R you can specify whether you want a comment to start with # or ## or ### or ... S Fra: mihai.mira...@bafin.de [mailto:mihai.mira...@bafin.de] Sendt: on 11-02-2009 10:54 Til: thierry.onkel...@inbo.be; Søren Højsgaard; r-help@r-project.org Emne: AW: [R] How to comment in R Still doesn't work. I did Format -- Block -- Comment and chose /* for begin comment, */ for end comment but R doesn't recognize the signs as such. Maybe I should work on the configuration of TINN R? Thanks, Mihai -Ursprüngliche Nachricht- Von: ONKELINX, Thierry [mailto:thierry.onkel...@inbo.be] Gesendet: Mittwoch, 11. Februar 2009 09:55 An: Mirauta, Mihai; soren.hojsga...@agrsci.dk; r-help@r-project.org Betreff: RE: [R] How to comment in R Via the menu choose: Format -- Block -- Comment Or use the shortcut key alt+C HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens mihai.mira...@bafin.de Verzonden: woensdag 11 februari 2009 9:47 Aan: soren.hojsga...@agrsci.dk; r-help@r-project.org Onderwerp: Re: [R] How to comment in R I am using Tinn-R. -Ursprüngliche Nachricht- Von: Søren Højsgaard [mailto:soren.hojsga...@agrsci.dk] Gesendet: Mittwoch, 11. Februar 2009 09:40 An: Mirauta, Mihai; r-help@r-project.org Betreff: SV: [R] How to comment in R A hash (#) anywhere on a line will comment out the rest of the line. Try! I don't think there is anything in R that will indicate the beginning and end of a comment section (like /* */ would in SAS). However most editors (and certainly emacs and Tinn-R) will allow you to comment out several lines. Søren Fra: r-help-boun...@r-project.org på vegne af mihai.mira...@bafin.de Sendt: on 11-02-2009 09:32 Til: r-help@r-project.org Emne: [R] How to comment in R Hi everybody, I use for the moment # at the begining of each line for comments. Is there any possibility to comment more than one line, like something which shows the beggingng and the end of the comment? Or is there a possibility to comment only a part of a line? Thanks, Mihai [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] faster version of split()?
Hi, R version 2.2.1 is slightly old. You may want to upgrade to the current version, R.2.8.1!!! You can for example do library(doBy) dd - data.frame(x=c(1,1,1,2,2,2), y=c(1,1,2, 1,1,1)) summaryBy(y~x, data=dd, FUN=function(x)length(unique(x))) Regards Søren -Oprindelig meddelelse- Fra: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] På vegne af Simon Pickett Sendt: 16. januar 2009 11:10 Til: R help Emne: [R] faster version of split()? Hi all, I want to calculate the number of unique observations of y in each level of x from my data frame df. this does the job but it is very slow for this big data frame (159503 rows, 11 columns). group.list - split(df$y,df$x) count - function(x) length(unique(na.omit(x))) sapply(group.list, count, USE.NAMES=TRUE) I couldnt find the answer searching for slow split and split time on help forum. I am running R version 2.2.1, on a machine with 4gb of memory and I'm using windows 2000. thanks in advance, Simon. - Original Message - From: Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no To: Gundala Viswanath gunda...@gmail.com Cc: R help r-h...@stat.math.ethz.ch Sent: Friday, January 16, 2009 9:30 AM Subject: Re: [R] Value Lookup from File without Slurping you might try to iteratively read a limited number of line of lines in a batch using readLines: # filename, the name of your file # n, the maximal count of lines to read in a batch connection = file(filename, open=rt) while (length(lines - readLines(con=connection, n=n))) { # do your stuff here } close(connection) ?file ?readLines vQ Gundala Viswanath wrote: Dear all, I have a repository file (let's call it repo.txt) that contain two columns like this: # tag value AAA0.2 AAT0.3 AAC 0.02 AAG 0.02 ATA0.3 ATT 0.7 Given another query vector qr - c(AAC, ATT) I would like to find the corresponding value for each query above, yielding: 0.02 0.7 However, I want to avoid slurping whole repo.txt into an object (e.g. hash). Is there any ways to do that? The reason I want to do that because repo.txt is very2 large size (milions of lines, with tag length 30 bp), and my PC memory is too small to keep it. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] summary with variance / sd
You can use summaryBy() in the doBy package: summaryBy(y+x~group, data=mydata, FUN=c(mean,sd)) Søren Fra: r-help-boun...@r-project.org på vegne af Jörg Groß Sendt: sø 11-01-2009 22:38 Til: r-help@r-project.org Emne: [R] summary with variance / sd Hi, I have a data frame and would like to have summary statistics for grouped data. With summary() I get the central tendencies for the overall data. How can I get descriptive statistics with variances and standard deviations? for example my data.frame: group x y exp 2 4 exp 3 5 exp 2 4 control 1 2 control 2 3 control 1 2 now I want tables with summary statistics (variances included) for each group. Is there an easy way to get this? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Memory Efficiency of Symmetric Matrix
You can do mat[lower.tri(mat, diag=F)] Søren Fra: r-help-boun...@r-project.org på vegne af Nathan S. Watson-Haigh Sendt: on 07-01-2009 01:28 Til: r-help@r-project.org Emne: [R] Memory Efficiency of Symmetric Matrix -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 I'm generating a symmetric correlation matrix using a data matrix as input: mat - cor(data.mat) My question is: Is there a more memory efficient way to store this data? For instance, since: all(mat == t(mat)) every value is duplicated, and I should be able to almost half the memory usage for large matrices. Any thoughts/comments? Cheers, Nathan - -- - Dr. Nathan S. Watson-Haigh OCE Post Doctoral Fellow CSIRO Livestock Industries Queensland Bioscience Precinct St Lucia, QLD 4067 Australia Tel: +61 (0)7 3214 2922 Fax: +61 (0)7 3214 2900 Web: http://www.csiro.au/people/Nathan.Watson-Haigh.html - -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org http://enigmail.mozdev.org/ iEYEARECAAYFAklj9yAACgkQ9gTv6QYzVL6MGQCg1CHsRGAwEMah/8ZuZ9QFI6O5 lcIAnjZ68DE9FABLMd07A3AfdMPRpXIH =5bet -END PGP SIGNATURE- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Summary information by groups programming assitance
Maybe summaryBy (or lapplyBy/splitBy) in the doBy package might help you. Regards Søren Fra: r-help-boun...@r-project.org på vegne af Ranney, Steven Sendt: ma 22-12-2008 22:51 Til: r-help@r-project.org Emne: [R] Summary information by groups programming assitance All - I have data that looks like psd Species Lake Length WeightSt.weightWr Wr.1 vol 432 substock SMB Clear150 41.00 0.01 95.12438 95.10118 0.0105 433 substock SMB Clear152 39.00 0.01 86.72916 86.70692 0.0105 434 substock SMB Clear152 40.00 3.11 88.95298 82.03689 3.2655 435 substock SMB Clear159 48.00 0.04 92.42095 92.34393 0.0420 436 substock SMB Clear159 48.00 0.01 92.42095 92.40170 0.0105 437 substock SMB Clear165 47.00 0.03 80.38023 80.32892 0.0315 438 substock SMB Clear171 62.00 0.21 94.58105 94.26070 0.2205 439 substock SMB Clear178 70.00 0.01 93.91912 93.90571 0.0105 440 substock SMB Clear179 76.00 1.38 100.15760 98.33895 1.4490 441 S-Q SMB Clear180 75.00 0.01 97.09330 97.08035 0.0105 442 S-Q SMB Clear180 92.00 0.02 119.10111 119.07522 0.0210 ... [truncated] where psd and lake are categorical variables, with five and four categories, respectively. I'd like to find the maximum vol and the lengths associated with each maximum vol by each category by each lake. In other words, I'd like to have a data frame that looks something like LakeCategoryLength vol Clear substock152 3.2655 Clear S-Q 266 11.73 Clear Q-P 330 14.89 ... Pickerelsubstock170 3.4965 PickerelS-Q 248 10.69 PickerelQ-P 335 25.62 PickerelP-M 415 32.62 PickerelM-T 442 17.25 In order to originally get this, I used with(smb[Lake==Clear,], tapply(vol, list(Length, psd),max)) with(smb[Lake==Enemy.Swim,], tapply(vol, list(Length, psd),max)) with(smb[Lake==Pickerel,], tapply(vol, list(Length, psd),max)) with(smb[Lake==Roy,], tapply(vol, list(Length, psd),max)) and pulled the values I needed out by hand and put them into a .csv. Unfortunately, I've got a number of other data sets upon which I'll need to do the same analysis. Finding a programmable alternative would provide a much easier (and likely less error prone) method to achieve the same results. Ideally, the Length and vol data would be in a data frame such that I could then analyze with nls. Does anyone have any thoughts as to how I might accomplish this? Thanks in advance, Steven Ranney __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Rcmd build problem: gcc.exe no input files (R.2.8.0 on Win XP)
Building a package using R.2.8.0 on Windows XP gives problems when compiling C code: Trying to run 'rcmd build' on R.2.8.0 on Windows XP gives ... -- Making package gRbase adding build stamp to DESCRIPTION making DLL ... gcc -std=gnu99 -Ic:/Programs/R/current/include gcc.exe: no input files make[3]: *** [setops.o] Error 1 make[2]: *** [srcDynlib] Error 2 make[1]: *** [all] Error 2 make: *** [pkg-gRbase] Error 2 *** Installation of gRbase failed *** whereas running 'rcmd build' on R.2.7.1 I get ... -- Making package gRbase adding build stamp to DESCRIPTION making DLL ... gcc -std=gnu99 -Ic:/programs/R/prev/include -O3 -Wall -c setops.c -o setops.o gcc -std=gnu99 -Ic:/programs/R/prev/include -O3 -Wall -c triangmcwh.c -o triangmcwh.o windres --preprocessor=gcc -E -xc -DRC_INVOKED -I c:/programs/R/prev/include -i gRbase_res.rc -o gRbase_res.o gcc -std=gnu99 -shared -s -o gRbase.dll gRbase.def setops.o triangmcwh.o gRbase_res.o -Lc:/programs/R/prev/bin -Lc:/programs/R/prev/bin -lRlapack -Lc:/programs/R/prev/bin -lRblas -lgfortran-lR ... DLL made - so the old version works fine. Would anyone have an idea what goes wrong? Thanks Søren [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Rcmd install problem: cannot open the connection and No such file or directory
Dear all, On Windows XP with R 2.8.0, I get the error message below when I try install a package from the command line. (Installing as a local zip-file from the menu in the GUI works fine.) Could anybody point me towards the source (and solution) to the problem? Regards Søren --- C:\Dokumenter\Stat\RLSdevelrcmd install RLS installing to '' installing R.css in -- Making package RLS adding build stamp to DESCRIPTION Error in file(file.path(outDir, DESCRIPTION), open = w) : cannot open the connection Calls: Anonymous - file In addition: Warning message: In file(file.path(outDir, DESCRIPTION), open = w) : cannot open file '/RLS/DESCRIPTION': No such file or directory Execution halted make[2]: *** [frontmatter] Error 1 make[1]: *** [all] Error 2 make: *** [pkg-RLS] Error 2 *** Installation of RLS failed *** Removing '/RLS' [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Exact test in nxm contingency table
Using r2dtable() you can simulate general tables nxm with given margins. Based on these you acn calculate a Monte Carlo p-value for a conditional test for independence. Regards Søren -Oprindelig meddelelse- Fra: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] På vegne af Magnus Pettersson Sendt: 17. september 2008 10:50 Til: r-help@r-project.org Emne: [R] Exact test in nxm contingency table Hello, I am trying to find a permutation test that works on a general nxm table. The data set is small enough to have cells with too small counts to make chi2-approximation invalid. If the table was a 2x2 contingency table I would like to use a Fsher exact test (fisher.test) but that wont work in this general table. Does there exist a general function for this test. Best regards, Magnus Pettersson Statistikkonsulterna Gårdavägen 1 412 50 Göteborg 0703-731297 www.statistikkonsulterna.se [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Extracting eg A[, , 3, 1, ] from an array but using dimension names and levels
Consider the extraction HairEyeColor[,3,1] Black Brown Red Blond 1025 7 5 Suppose I have the appropriate dimensions and levels given as variables, e.g. d1 -2 l1 -3 d2 -3 l2 -1 How can I then make the extraction above using d1, l1, d2, l2 (for an array of arbitrary dimension)? Best regards Søren __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Exponential smoothing?
Try ?HoltWinters and ?filter Regards Søren -Oprindelig meddelelse- Fra: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] På vegne af Öhagen Patrik Sendt: 19. august 2008 10:00 Til: R hELP Emne: [R] Exponential smoothing? Dear List, I have used all my resources (i.e. help.search) and I still havn't been able to figure out if there is an Exponential Smoothing command in R. Thank you in advance! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to build a package which loads Rgraphviz (if installed)...
Dear List, I use Rgraphviz for display of graphs in some packages. Since Rgraphviz is no longer on CRAN it needs to be installed from Bioconductor and that is fine, but I have trouble figureing out the following: I create a plot method which - if Rgraphviz is installed - uses Rgraphviz for displaying and otherwise does nothing. This is implemented as: if (!(package:Rgraphviz %in% search())){ if(Rgraphviz %in% installed.packages()){ require(Rgraphviz) } else { cat(The Rgraphviz package (from Bioconductor) must be installed to display the models\n) return() } } ... else go on and do the plotting... When I run rcmd check packagename (on Windows XP, using R.2.7.1) I get * checking for unstated dependencies in R code ... WARNING 'library' or 'require' calls not declared from: Rgraphviz See the information on DESCRIPTION files in the chapter 'Creating R packages' of the 'Writing R Extensions' manual. I can not state Rgraphviz in the Depends-field of the DESCRIPTION file because then the package does not pass the windows checks for going on CRAN. I can not see any solution from writing R extensions, but I apologize if I have overlooked it. Does anyone have a suggestion on what to do? Cheers Søren __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 build a package which loads Rgraphviz (if installed)...
Bill, Thanks for the suggestion, but it does not solve the problem; I get the same warning from rcmd check. I suspect that rcmd check actually checks that any package referred to in require() is declared in the DESCRIPTION file. From the version numbers from your 'psych' package I guess you are stuck with the same problem??? Cheers Søren Fra: William Revelle [mailto:[EMAIL PROTECTED] Sendt: lø 12-07-2008 23:47 Til: Søren Højsgaard; [EMAIL PROTECTED] Emne: Re: [R] How to build a package which loads Rgraphviz (if installed)... Soren, When I had an almost identical problem last year. I also wanted to use Rraphviz but only if people had it. Kurt Hornik suggested that I replace a direct call to the function, foo, that uses Rgraphviz with if(require(Rgraphviz)) foo() Bill At 10:23 PM +0200 7/12/08, Søren Højsgaard wrote: Dear List, I use Rgraphviz for display of graphs in some packages. Since Rgraphviz is no longer on CRAN it needs to be installed from Bioconductor and that is fine, but I have trouble figureing out the following: I create a plot method which - if Rgraphviz is installed - uses Rgraphviz for displaying and otherwise does nothing. This is implemented as: if (!(package:Rgraphviz %in% search())){ if(Rgraphviz %in% installed.packages()){ require(Rgraphviz) } else { cat(The Rgraphviz package (from Bioconductor) must be installed to display the models\n) return() } } ... else go on and do the plotting... When I run rcmd check packagename (on Windows XP, using R.2.7.1) I get * checking for unstated dependencies in R code ... WARNING 'library' or 'require' calls not declared from: Rgraphviz See the information on DESCRIPTION files in the chapter 'Creating R packages' of the 'Writing R Extensions' manual. I can not state Rgraphviz in the Depends-field of the DESCRIPTION file because then the package does not pass the windows checks for going on CRAN. I can not see any solution from writing R extensions, but I apologize if I have overlooked it. Does anyone have a suggestion on what to do? Cheers Søren __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Attend ISSID/ARP:2009 http://issid.org/issid.2009/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 build a package which loads Rgraphviz (if installed)...
The tricky part is not getting it through the checks on my computer. It is when I upload to CRAN I get the problems, because their computers need Rgraphviz as well... (Suggests does not seem to be the solution...) Cheers Søren Fra: Duncan Murdoch [mailto:[EMAIL PROTECTED] Sendt: sø 13-07-2008 00:36 Til: Søren Højsgaard Cc: William Revelle; [EMAIL PROTECTED] Emne: Re: [R] How to build a package which loads Rgraphviz (if installed)... On 12/07/2008 6:27 PM, Søren Højsgaard wrote: Bill, Thanks for the suggestion, but it does not solve the problem; I get the same warning from rcmd check. I suspect that rcmd check actually checks that any package referred to in require() is declared in the DESCRIPTION file. From the version numbers from your 'psych' package I guess you are stuck with the same problem??? There are varying degrees of dependence. Probably Suggests is what you want. Note that *you* need to have RGraphViz to make it through the checks, but other users won't need it. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.