Re: [R] Help with Data Transformation

2011-01-11 Thread ONKELINX, Thierry
Dear Guy, Have a look at cast() from the reshape package. You'll need something like cast(fldsampleid ~ Analysis, value = "Result", data = your.data.frame) Best regards, Thierry ir. Thierry Onkelinx Instituut voor na

Re: [R] add a linear regression line to the plot

2011-01-13 Thread ONKELINX, Thierry
Such things are very easy with the ggplot2 package install.packages("ggplot2") library(ggplot2) Dataset <- data.frame(A = c(10,20,40,80), B = c(30,40,100,200)) ggplot(data = Dataset, aes(x = A, y = B)) + geom_point() + geom_smooth(method = "lm") More info and example on the ggplot2 website: http:

Re: [R] bug in qplot (library ggplot2)

2011-01-14 Thread ONKELINX, Thierry
Pierre, You did not look hard enough. You need FAQ 7.22 http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur-

Re: [R] bug in qplot (library ggplot2)

2011-01-14 Thread ONKELINX, Thierry
Dear Pierre, A more elegant solution is to use ggsave() library(ggplot2) for (i in 1:2) { p <- qplot(carat, data=diamonds, fill=color,geom='histogram')+scale_y_continuous(i) ggsave(filename = paste('test ',i,'.png',sep=''), plot = p) } Best regards, Thierry --

Re: [R] test

2011-01-14 Thread ONKELINX, Thierry
Here is a more elegant solution using the plyr package. my.data <- expand.grid(Thesis = 1:3, Day = c(0, 14), Run = 1:10) my.data$A <- rpois(nrow(my.data), 10) my.data$B <- rpois(nrow(my.data), 10) my.data$C <- rpois(nrow(my.data), 10) library(plyr) ddply(my.data, .(Thesis, Day), function(x){

Re: [R] complex transformation of data

2011-01-21 Thread ONKELINX, Thierry
Denis, Have a look at paste(), aggregate(), ddply() (from the plyr package) and melt() and cast() (both from the reshape package). Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team

Re: [R] precision of minus operation and if statments

2010-07-29 Thread ONKELINX, Thierry
This is FAQ 7.31: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie & Kwaliteitszorg Gaverstraat

Re: [R] Fwd: duplicates

2010-07-29 Thread ONKELINX, Thierry
Does this works? (Untested) library(plyr) ddply(your_dataframe, "var1", function(x){ x[which.max(x$var2), ] }) ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie & Kwaliteitszorg Gaverstr

Re: [R] Residuals of mixed effects model

2010-07-29 Thread ONKELINX, Thierry
Dear Will, residuals() should take both the fixed and random effects into account. Can you give us a reproducible example if you get something different? Use residuals(model, type = "normalized") if you also want to account for the correlation structure. What do you want to do with the residuals

Re: [R] Yet another memory limit problem

2010-08-18 Thread ONKELINX, Thierry
Dear Tim, Are mydat$Date and mydat$Time what you think they are? What output do you get from str(mydat)? HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie & Kwaliteitszorg Gaverst

Re: [R] R reports

2010-08-19 Thread ONKELINX, Thierry
Dear Donald, I'm not sure what the meaning of '3G' and '4G' is. You should take a look at Sweave() which is a very powerfull tool for generating reports in R. HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- e

Re: [R] Quick q. on lists

2010-08-19 Thread ONKELINX, Thierry
You need sapply max(sapply(myList, nrow)) Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie & Kwaliteitszorg Gaverstraat 4 9500 Geraardsbergen Belgium Research Institute for Nature and

Re: [R] compare three values

2010-08-30 Thread ONKELINX, Thierry
Have a look at switch() and which.min() x <- c(a = 3, b = 1, c = 5) switch(which.min(x), "a is lowest", "b is lowest", "c is lowest") HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biome

Re: [R] ggplot2 multiple group barchart

2010-09-02 Thread ONKELINX, Thierry
Dear Greg, First convert your data.frame to a long format using melt(). Then use ddply() to calculate the averages. Once you get at this point is should be rather straightforward. library (ggplot2) v1 <- c(1,2,3,3,4) v2 <- c(4,3,1,1,9) v3 <- c(3,5,7,2,9) gender <- c("m","f","m","f","f") d.da

Re: [R] reshape to wide format takes extremely long

2010-09-02 Thread ONKELINX, Thierry
Dear Dennis, cast() is in this case much faster. > system.time(bigtab <- ddply(big, .(study, subject, cycle, day), function(x) xtabs(obs ~ type, data = x))) user system elapsed 35.360.12 35.53 > system.time(bigtab2 <- cast(data = big, study + subject + cycle + day ~type, value = "ob

Re: [R] nlme formula from model specification

2010-09-02 Thread ONKELINX, Thierry
Dear Mikkel, You need to do some reading on terminology. In your model the fixed effects are channel 1, 2 and 3. samplenumber is a random effect and the error term is an error term The model you described has the notation below. You do not need to create the grouped data structure. lme(channel0

Re: [R] nlme Output

2010-09-06 Thread ONKELINX, Thierry
Dear Edward, You have no degrees of freedom left to estimate those p-values. Your design does not allows for the model your implemented. We need a brief summary of your design in order to help you further. HTH, Thierry ---

Re: [R] rbind() overwriting data.frame()

2010-09-06 Thread ONKELINX, Thierry
This will give a matrix with 0 rows. data.frame(matrix(nrow = 0, ncol = 22, dimnames = list(NULL, LETTERS[1:22]))) But you should avoid growing dataframes is the final dataframe is going to be large. You are very likely to get memory problems. It is much to better to create a large enough datafr

Re: [R] nlme Output

2010-09-07 Thread ONKELINX, Thierry
data. ~ John Tukey Van: Edward Patzelt [mailto:patze...@umn.edu] Verzonden: dinsdag 7 september 2010 0:25 Aan: ONKELINX, Thierry CC: r-help@r-project.org Onderwerp: Re: [R] nlme Output The design is a repeat

Re: [R] Something similar to layout in lattice or ggplot

2010-09-07 Thread ONKELINX, Thierry
Dear Abhijit, In ggplot you can use facetting (facet_grid() or facet_wrap()) to create subplot based on the same dataset. Or you can work with viewport() if you want several independent plots. HTH, Thierry ir. Thierr

Re: [R] Assignments inside lapply

2011-04-27 Thread ONKELINX, Thierry
Dear Alex, I think you want to use apply() ij <- expand.grid(i = seq_len(dimx),j = seq_len(dimy)) Powermap <- apply(ij, 1, function(x){ Pr(x, c(PRX, PRY), f) }) Best regards, Thierry ir. Thierry Onkelinx Insti

Re: [R] Assignments inside lapply

2011-04-27 Thread ONKELINX, Thierry
an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey > -Oorspronkelijk bericht- > Van: Alaios [mailto:ala...@yahoo.com] > Verzonden: woensdag 27 april 2011 12:14 > Aan: R-help@r-project.org; ONKELINX, Thierry > Onde

[R] Coding design with repeated measurements in the survey package

2011-04-28 Thread ONKELINX, Thierry
Dear all, I'm working on a design with rotating panels. Each site is sampled every X year. Have a look at the code below the get an idea of the design. In reality the number of sites will be (much) higher. However I'm not sure if I coded the design correctly in svydesign(). Can someone confirm

Re: [R] using lme4 with three nested random effects

2011-04-29 Thread ONKELINX, Thierry
Dear Ben, Are site, transect and plot factors? And do they have unique id's? You could try this rws30.UL$site <- factor(rws30.UL$site) rws30.UL$transect <- interaction(rws30.UL$site, rws30.UL$transect, drop = TRUE) rws30.UL$plot <- interaction(rws30.UL$site, rws30.UL$transect, rws30.UL$plot, d

Re: [R] barplot groups of different size i.e. height is NOT a matrix

2011-05-25 Thread ONKELINX, Thierry
Dear Victor, Here is a basic solutions using ggplot2 library(ggplot2) dataset <- data.frame(Main = c("A", "A", "A", "B", "B"), Detail = c("a", "b", "c", "1", "2"), value = runif(5, min = 0.5, max = 1)) ggplot(dataset, aes(x = Detail, y = value)) + geom_bar() + facet_grid(.~Main, scales = "free_

Re: [R] different results from lme() and lmer()

2011-06-01 Thread ONKELINX, Thierry
Dear Miya, Notice the very strong negative correlation between the random intercept and the random slope in the lme() model. That is usually an indication of problems (in this case overfitting). If you drop the random slope, then both models yield the same parameters. Plotting the data reviels

Re: [R] Identifying sequences

2011-06-01 Thread ONKELINX, Thierry
Something like this? a=1:10 b=20:30 c=40:50 x=c(a,b,c) borders <- which(diff(x) != 1) seqs <- data.frame(start = c(1, borders + 1), end = c(borders, length(x))) Best regards, Thierry > -Oorspronkelijk bericht- > Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > N

Re: [R] barplot in ggplot2

2010-05-11 Thread ONKELINX, Thierry
Dear Joshua, You can accomplish that by setting the position argument in geom_bar to position_dodge(width = 0). ggplot(plot.means, aes(x=index, y=means, fill=factor(hilow))) + geom_bar(position = position_dodge(width = 0.1), stat="identity") But such a plot can be very misleading. Therefore I

Re: [R] Mixed Effects Model on Within-Subjects Design

2010-05-20 Thread ONKELINX, Thierry
Dear Dave, I think you want this model. lme(value~condition:diff - 1,random=~1|subject) Note that I removed the replicate ID from the model. Include it in the model makes only sense if you can expect a similar replication effects the first/second/thirth time that a subject performs your test.

Re: [R] Mixed Effects Model on Within-Subjects Design

2010-05-20 Thread ONKELINX, Thierry
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: der...@gmail.com [mailto:der...@gmail.com] Namens Dave Deriso > Verzonden: donderdag 20 mei 2010

Re: [R] lme: model variance and error by group

2010-05-21 Thread ONKELINX, Thierry
Have a look at ?varClasses. You could you something like varIdent(form = ~ 1|areatrai) or varExp(form = ~areatrai) R-sig-mixed-models is a better list for this kind of questions. Thierry ir. Thierry Onkelinx Instituut

Re: [R] adding column to data frame conditionally

2010-05-27 Thread ONKELINX, Thierry
Dear Kristina, Use ifelse(). Note that you must use '==' to test for equality. '=' is an assignment. Freqg$condition <- with(freqg, ifelse(mat==1 & flank==1, 1, ifelse(mat == 2 & flank == 1, 2, NA))) HTH, Thierry ir.

Re: [R] Getting sink to work with "message" on R 2.11.0 - what didImiss?

2010-05-27 Thread ONKELINX, Thierry
Dear Faiz, Maybe the xtable package can be helpfull for you. It adds markup tags to a table. You can choose between LaTeX and HTML. Microsoft can open HTML files. HTH, Thierry ir. Thierry Onkelinx Instituut voor natuu

Re: [R] Handing significance digits

2010-05-28 Thread ONKELINX, Thierry
You can use round(value, 2) ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie & Kwaliteitszorg Gaverstraat 4 9500 Geraardsbergen Belgium Research Institute for Nature and Forest team Biometrics

Re: [R] barchart but with boxes

2010-06-07 Thread ONKELINX, Thierry
Dear Daisy, This is easy woth ggplot2. Use geom_crossbar() and set the middle bar at the minimum of maximum. library(ggplot2) dataset <- data.frame(catg = (c(1,2,3,2,4,3,2,1,4,3,1)), min = (c(1,2,3,3,4,5,6,6,3,2,1)), max = (c(10,6,8,6,7,3,10,9,10,8,9))) ggplot(dataset, aes(x = catg, y = min, ym

Re: [R] Multiply Two Dataframes

2010-06-07 Thread ONKELINX, Thierry
Dear Bert, The easiest thing would be to merge both datasets and then multiply the corresponding columns. both <- merge(df1, df2) both[, 3:22] * both[, 23:42] HTH, Thierry -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org namens Bert Jacobs Verzonden: ma 7-6-2010 20:29 Aan: r

Re: [R] specifying plot symbol sizes in qplot or ggplot2

2010-06-09 Thread ONKELINX, Thierry
Have a look at ?scale_size_manual() HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie & Kwaliteitszorg Gaverstraat 4 9500 Geraardsbergen Belgium Research Institute for Nature and

Re: [R] drawing curve

2010-06-10 Thread ONKELINX, Thierry
Have a look at the ggplot2 package x <- 1:6 y <- c(.01,.09,.08,.03,.001,.02) dataset <- data.frame(x, y) library(ggplot2) ggplot(data = dataset, aes(x = x , y = y)) + geom_smooth() ggplot(data = dataset, aes(x = x , y = y)) + geom_smooth() + geom_point() ggplot(data = dataset, aes(x = x , y = y))

Re: [R] Sweave cutting new lines

2010-06-10 Thread ONKELINX, Thierry
Hi Florian, Have you tried to replace each '\n' with '\r\n'. That did the trick for me. HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie & Kwaliteitszorg Gaverstraat 4 9500 Geraa

Re: [R] Ggplot: free x-scales in a facet-grid

2011-02-11 Thread ONKELINX, Thierry
Dear Ann, The easiest way is to seperate both plots into two subplots. And then use viewport to paste them together. Best regards, Thierry p1 <- ggplot(subset(data.melt, pos = "FALSE"),aes(value,ID)) + geom_point(aes(groups=time,colour=time,shape=time)) + facet_grid(type~.,scales="fr

Re: [R] removing lower and upper quantiles from an arry

2011-02-17 Thread ONKELINX, Thierry
You need two logical test and then combine them with & (AND) or | (OR) i[quantile(i,.25) >= i & i <= quantile(i,.75)] Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie & K

Re: [R] multiple plots using a loop

2011-02-21 Thread ONKELINX, Thierry
It is also a one-liner with ggplot2 dataset <- data.frame(Factor = rep(factor(letters[1:4]), each = 10), Size = runif(40) * 100) library(ggplot2) ggplot(dataset, aes(x = Size)) + geom_histogram() + facet_wrap(~Factor) --

Re: [R] count data

2011-02-25 Thread ONKELINX, Thierry
Dear Sacha, Do you revisit the same locations per site? If so, use (1|site/location) as random effect. Otherwise use just (1|site). You might want to add a crossed random effect (1|date) if you can expect an effect of phenology. Best regards, Thierry PS R-sig-mixed-models is a better list for

Re: [R] Zero Inflated Distributions

2011-03-04 Thread ONKELINX, Thierry
library(sos) findFn("Zero Inflated Lognormal") ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie & Kwaliteitszorg Gaverstraat 4 9500 Geraardsbergen Belgium Research Institute for Nature and Fores

Re: [R] plotCI() with ggplot2

2011-03-08 Thread ONKELINX, Thierry
Have a look at the examples of geom_errorbar() at the website: http://had.co.nz/ggplot2/geom_errorbar.html Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie & Kwaliteitszo

Re: [R] NaNs in Nested Mixed Model

2011-03-09 Thread ONKELINX, Thierry
Dear Johan, A few remarks. - R-sig-mixed models is a better list for asking questions about mixed model. - I presume that Nymphs is the number of insects? In that case you need a generalised linear (mixed) model with poisson family - What are you interessed in? The variability among genotypes or

Re: [R] increase a value by each group?

2011-03-14 Thread ONKELINX, Thierry
Something like this? my_data=read.table("clipboard", header=TRUE) my_data$s_name <- factor(my_data$s_name) library(plyr) ddply(my_data, .(s_name), function(x){ x$Im_looking <- x$Depth + as.numeric(x$s_name) / 100 x }) Best regards, Thierry ---

Re: [R] lmm WITHOUT random factor (lme4)

2011-03-17 Thread ONKELINX, Thierry
Dear Mark, You cannot compare lm() with lme() because the likelihoods are not the same. Use gls() instead of lm() library(nlme) data("sleepstudy", package = "lme4") fm <- lm(Reaction ~ Days, sleepstudy) fm0 <- gls(Reaction ~ Days, sleepstudy) logLik(fm) logLik(fm0) fm1 <- lme(Reaction ~ Days, r

Re: [R] lmm WITHOUT random factor (lme4)

2011-03-18 Thread ONKELINX, Thierry
Dear Mark, I'm cc'ing this to the mixed models list to get some input from other experts. For them a link to the entire thread: http://r.789695.n4.nabble.com/lmm-WITHOUT-random-factor-lme4-tp3384054p3384823.html My comment was based on what I have read in Zuur et al. (2009). What worries me i

Re: [R] R as a non-functional language

2011-03-21 Thread ONKELINX, Thierry
Dear Russ, Why not use simply pH <- c(area1 = 4.5, area2 = 7, mud = 7.3, dam = 8.2, middle = 6.3) That notation is IMHO the most readable for students. Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur

Re: [R] Using graphics straight from R into published articles

2011-03-30 Thread ONKELINX, Thierry
Large snip. > Absolutely vector - no jpeg, png, ... although it takes > sometimes some convincing of co-authors... > That depends on the kind of graph. I aggree that you should try vector at first. But when it generates very larges files (e.g. scatterplots with thousands of points) then you

Re: [R] Violin Plot - using ggplot2

2011-03-30 Thread ONKELINX, Thierry
Dear JP, Please do not cross post between lists. Here is a possible solution. library(ggplot2) p <- rep(c(rep("condition_a", 4), rep("condition_b", 4)), 2) q <- c(rep("grp_1", 8), rep("grp_2", 8)) r <- sample(1:5, 16, rep = T) d <- data.frame(p, q, r) ggplot(d, aes(x = r)) + geom_ribbon(aes(ymax

Re: [R] That dreaded floating point trap

2011-03-31 Thread ONKELINX, Thierry
Dear Alexander, Instead of testing 'somevector > 0.4', test 'abs(somevector - 0.4) < some.small.number' Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie & Kwaliteitszorg

Re: [R] Syntax coloring in R console

2011-04-01 Thread ONKELINX, Thierry
Dear January, Have a look at Eclipse with the STAT-ET plugin http://www.walware.de/goto/statet Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie & Kwaliteitszorg Gaverstra

Re: [R] Euclidean Distance in R

2011-04-05 Thread ONKELINX, Thierry
Dear Paul, The command RSiteSearch("nearest neighbour") Will give you the answer that you need. (The second hit is the function you want). Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonde

Re: [R] Sweave : allowing errors in R code?

2011-08-09 Thread ONKELINX, Thierry
Dear Remko, Here is a working example on what Duncan suggested. Best regards, Thierry <>= TheObject <- "Something" ls() rm("TheObject") @ %outputs the R code but does not execute it. So no error <>= TheObject @ % executes the code but displays only the error <>= cat(try(TheObject)) @ > -

Re: [R] Source Code glm() question

2011-08-10 Thread ONKELINX, Thierry
Just type glm at the prompt. > glm function (formula, family = gaussian, data, weights, subset, na.action, start = NULL, etastart, mustart, offset, control = list(...), model = TRUE, method = "glm.fit", x = FALSE, y = TRUE, contrasts = NULL, ...) { call <- match.call() if (

Re: [R] rbind/cbind

2011-08-10 Thread ONKELINX, Thierry
Can't you use sapply? sapply(seq_len(10), function(i){SomeExpression(i)}) Best regards, Thierry > -Oorspronkelijk bericht- > Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > Namens David Winsemius > Verzonden: woensdag 10 augustus 2011 15:50 > Aan: Anthony Ching

Re: [R] Time series and ggplot2

2011-08-23 Thread ONKELINX, Thierry
Without a reproducilbe example, it is hard to give you good advise... > -Oorspronkelijk bericht- > Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > Namens ashz > Verzonden: maandag 22 augustus 2011 23:53 > Aan: r-help@r-project.org > Onderwerp: [R] Time series and

Re: [R] Power analysis in hierarchical models

2011-09-12 Thread ONKELINX, Thierry
Dear Tom, I think you failed to generate simulated outcome from the correct model. Hence the zero variance of your random effects. Here is a better working example. library(lme4) fake2 <- expand.grid(Bleach = c("Control","Med","High"), Temp = c("Cold","Hot"), Rep = factor(seq_len(3)), ID = seq

Re: [R] R 2.13.1 console echo problem or am I wrong?

2011-09-14 Thread ONKELINX, Thierry
Have you tried adding print() statements? e.g. changing summary(x) to print(summary(x)) Posting a reproducible example would help us. Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek t

Re: [R] Function for running a sign test

2011-09-19 Thread ONKELINX, Thierry
You did not search hard enough. RSiteSearch("sign test") or library(sos) findFn("sign test") Both gives you plenty of possible functions. > -Oorspronkelijk bericht- > Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > Namens Paul Smith > Verzonden: maandag 19 sep

Re: [R] Transform counts into presence/absence

2012-05-31 Thread ONKELINX, Thierry
Just use the logical operators. Counts <- c(1,0,21,2,0,0,234,2,0) Counts > 0 1 *(Counts > 0) ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25 1070 Anderlec

Re: [R] Two-way linear model with interaction but without one main effect

2012-06-12 Thread ONKELINX, Thierry
Dear Helios, I think you rather want a mixed model with shoe as random effect. library(lme4) lmer(Y ~ Ground + (1|Shoe)) #the effect of shoe is independent of the ground effect or lmer(Y ~ Ground + (0 + Ground|Shoe)) #the effect of shoe is different per ground. Best regards, Thierry ir. Thie

Re: [R] R-SCRIPT Label Calling Method

2012-06-12 Thread ONKELINX, Thierry
Is this homework? If it is, please read the posting guide. ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium + 32 2 525 02 51 + 32 54

Re: [R] lme random slope results the same as random slope and intercept model

2012-06-12 Thread ONKELINX, Thierry
Dear John, R-sig-mixed-models is a better list for this kind of questions. It looks like the model finds no evidence for a random slope. Notice the very small variance of the random slope. In the model without random intercept, the random slope tries to mimic the effect of a random intercept.

Re: [R] lme: extract result-function

2012-06-13 Thread ONKELINX, Thierry
Dear Christof, You want the predict() function. See ?predict.lme for the details. Best regards, Thierry PS Questions on lme() can be asked at r-sig-mixed models. ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitsz

Re: [R] assign object with loop (translation from SAS to R)

2012-06-29 Thread ONKELINX, Thierry
You can use a combination of the outer() and apply() functions n <- 10 p <- 9 dataset <- data.frame(matrix(rep(seq_len(p), each = n), nrow = n, ncol = p)) colnames(dataset) <- paste("p", seq_len(p), sep = "") test <- t(apply(dataset, 1, function(x){ x %o% x})) colnames(test) <- paste("p", rep(seq_

Re: [R] CPU usage while running R code

2012-07-04 Thread ONKELINX, Thierry
Dear Laurent, An R proces uses only one core. It is possible to use multiple cores. Have a look at he Hig-Performance and Parallel Computing task view (http://cran.freestatistics.org/web/views/HighPerformanceComputing.html) Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur- en

Re: [R] How to run zero inflated mixed model and hurdle mixed model in R

2011-06-14 Thread ONKELINX, Thierry
Have a look at the MCMCglmm package. http://www.freestatistics.org/cran/web/packages/MCMCglmm/vignettes/Overview.pdf Best regards, Thierry > -Oorspronkelijk bericht- > Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > Namens Xiongqing Zhang > Verzonden: dinsdag 1

Re: [R] Side by side scatter plots with specified regression lines

2011-06-15 Thread ONKELINX, Thierry
Dear Sigrid, This is very easy with the ggplot2 package install.packages("ggplot2") library(ggplot2) ggplot(data = Your.Data.Frame, aes(x = YEAR, y = YIELD, colour = TREATMENT)) + geom_point() + geom_smooth(method = "lm") + facet_wrap(~Country) Best regards, Thierry > -Oorspronkelijk beri

Re: [R] Column of numbers added to dataframe when saving with read.csv

2011-06-15 Thread ONKELINX, Thierry
Reading the helpfile (as the posting guide asks you to do) of write.table will solve your problem. > -Oorspronkelijk bericht- > Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > Namens Paolo Rossi > Verzonden: woensdag 15 juni 2011 16:52 > Aan: r-help@r-project.org

Re: [R] Multiple (7) Y axes?

2011-06-16 Thread ONKELINX, Thierry
Dear Philip, If the values are not important, then you don't need different Y-axes. Why not standardise the seven datasets so they have a common scale? Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur-

Re: [R] Points but no lines in qplot.

2011-06-30 Thread ONKELINX, Thierry
This is probably due to a numerical value that is coded as a factor. Have a look at the example below. In ggplot2 one line per group is plotted. The default grouping is the combination of all factors. In the first example only B, in the second and third example both A and B. This leaves just one

Re: [R] Poisson GLM with a logged dependent variable...just asking for trouble?

2011-07-04 Thread ONKELINX, Thierry
Dear Mark, I think you want glm(DV ~ log10(IV), family=poisson) Note that the poisson family uses the log-link by default. Hence you don't need to log-transform DV yourself. Best regards, Thierry ir. Thierry Onkelinx

Re: [R] Unusual graph- modified wind rose perhaps?

2011-07-04 Thread ONKELINX, Thierry
Dear John, You can get pretty close with ggplot2. Best regards, Thierry library(ggplot2) dataset <- data.frame(Name = LETTERS[1:26]) dataset$Score <- runif(nrow(dataset)) dataset$Category <- cut(dataset$Score, breaks = c(-Inf, 0.33, 0.66, Inf), labels = c("Bad", "Neutral", "Good")) dataset$Nam

Re: [R] For help in R coding

2011-07-05 Thread ONKELINX, Thierry
Dear Vikas, Have at look at ?merge() Best regards, Thierry > -Oorspronkelijk bericht- > Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > Namens Bansal, Vikas > Verzonden: dinsdag 5 juli 2011 16:51 > Aan: David Winsemius > CC: r-help@r-project.org > Onderwerp: Re

Re: [R] Meaning of "%%"

2011-07-13 Thread ONKELINX, Thierry
help("%%") ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie & Kwaliteitszorg Gaverstraat 4 9500 Geraardsbergen Belgium Research Institute for Nature and Forest team Biometrics & Quality Assuranc

Re: [R] LME and overall treatment effects

2011-07-15 Thread ONKELINX, Thierry
Dear Mark, Interpreting one of the main effects when they are part of an interaction is, AFAIK, not possible. Your statement about comparing treatments when Year is continuous is not correct. The parameters of treatment assume that Year == 0! Which might lead to very strange effect when year is

Re: [R] lme convergence error

2011-07-26 Thread ONKELINX, Thierry
Dear Ben, Maybe the model converges more slowy than other models. Running more iterations might solve the problem. Have a look at ?lme and ?lmeControl. Best regards, Thierry PS R-sig-mixedmodels is a better list for questions on lme(). -

Re: [R] help with regression

2011-07-26 Thread ONKELINX, Thierry
Dear Joe, You need to use offset() lm(y ~ a + offset(b) + c) Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie & Kwaliteitszorg Gaverstraat 4 9500 Geraardsbergen Belgium

Re: [R] how to replace values in x by means in subgroups created in ... (not loops)

2011-07-27 Thread ONKELINX, Thierry
Something like this? dataset <- data.frame(x = x, y = y) dataset$Group <- cumsum(c(0, diff(!is.na(dataset$y) & dataset$y == 0)) == 1) library(plyr) tmp <- ddply(subset(dataset, y == 0), .(Group), function(z){c(Mean = mean(z$x, na.rm = TRUE))}) result <- merge(dataset, tmp) result$Mean[is.na(resul

Re: [R] ggplot2 help/suggestions needed

2011-07-29 Thread ONKELINX, Thierry
Dear Bruce, It's doable with ggplot2, but image() is probably a better solution. To use ggplot2, you will need to convert your array into a data.frame where each row has the information for one cell (x, y and colour) library(ggplot2) #create some dummy data dataset <- expand.grid(x = seq_len(10

Re: [R] R in Linux (Ubuntu)

2011-07-29 Thread ONKELINX, Thierry
Dear Mario, Have a look at Eclipse with the StatET plugin. One of the benefits is that is available for both Linux and Windows which simplifies things when you need to switch often between Windows and Linux (e.g. Windows at work and Linux at home). Best regards, Thierry --

Re: [R] Loops to assign a unique ID to a column

2011-08-02 Thread ONKELINX, Thierry
Dear Chandra, You're on the wrong track. You don't need for loops as you can do this vectorised. as.numeric(interaction(data$Groups, data$Dates, drop = TRUE)) Best regards, Thierry > -Oorspronkelijk bericht- > Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > N

Re: [R] slow computation of functions over large datasets

2011-08-03 Thread ONKELINX, Thierry
Dear Caroline, Here is a faster and more elegant solution. > n <- 1 > exampledata <- data.frame(orderID = sample(floor(n / 5), n, replace = TRUE), > itemPrice = rpois(n, 10)) > library(plyr) > system.time({ + ddply(exampledata, .(orderID), function(x){ + data.frame(itemPr

Re: [R] Error Bars ggplot2

2012-07-27 Thread ONKELINX, Thierry
How about this? Andpleasemakeusofthelargekeyatthebottomofyourkeyboard.Itmakescodemuchmorereadable. library(ggplot2) spd <- factor(c("s","f","f","s","f","s","s","s","f","f","s","f")) r <- c(4.9,3.2,2.1,.2,3.8,6.4,7.5,1.7,3.4,4.1,2.2,5) dataset <- data.frame(spd, r) dataset <- rbind(cbind(dataset,

Re: [R] producing a graph with glm poisson distributed respons count data and categorical independant variables

2012-07-27 Thread ONKELINX, Thierry
Dear Babs, This is how I would present the model, if I had enough data to support the model. The model is too complicated for your data and leads to a perfect fit. Is this the aggregated dataset, or does your design has no replicates? Best regards, Thierry dataset$combinatie <- dataset$proefo

Re: [R] Simple question about formulae in R!?

2012-08-10 Thread ONKELINX, Thierry
Dear Johan, Why should it be complicated? You have a very simple model, thus a very simple formula. Isn't that great? Your formula matches the model. Though Trust~Culture + Structure * Speed_of_Integration is another option. The model fit is the same, the only difference is the parameterizatio

Re: [R] hierachical code system

2011-11-16 Thread ONKELINX, Thierry
Dear Albert-Jan, The easiest way is to create extra variables with the corresponding aggregation level. substr() en strsplit() can be your friends. Once you have those variables you can use aggregate() or any other aggregating function. You don't need loops. Best regards, Thierry > -Oors

Re: [R] How to resample one per group

2011-11-17 Thread ONKELINX, Thierry
Something like this? library(plyr) ddply(df, .(group), function(x){ x[sample(nrow(x), 1), ] }) Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie & Kwaliteitszorg Gaverst

Re: [R] [OT] 1 vs 2-way anova technical question

2011-11-21 Thread ONKELINX, Thierry
Giovanni, Have you tried Bert suggestion 2)? Because his log(R) ~ A*B + C + D is NOT the same as your log(R)~A+B+I(A*B)+C+D Note that I(A * B) means: create a new variable that is the product of A and B. Which is not meaningfull if A and B are factors (hence the warning you got). So I(A * B) is

Re: [R] errors with lme4

2011-11-22 Thread ONKELINX, Thierry
Dear Alessio, A few remarks. - R-sig-mixed models is a better list for this kind of questions - use the glmer() function if you want logistic or poisson regression - the error you are getting is an indication that the model is too complex for the data - watch for colinearity in the covariates B

[R] data.table merge equivalent for all.x

2011-11-26 Thread ONKELINX, Thierry
Dear all, I'm trying to use data.table to summarise a table and merge it to another table. Here is what I would like to do, but by using data.table() in a proper way. library(data.table) tab1 <- data.table(ID = 11:20, A = rnorm(10), D = 1:10, key = "ID") tab2 <- data.table(ID2 = 1:10, D = rep(1

Re: [R] Regression model when dependent variable can only take positive values

2011-12-06 Thread ONKELINX, Thierry
Dear Michael, Did you measure newborns? If not center age to a value that makes sense in relation with the range of age in your dataset. Then the intercept will be the height at the reference age. And most likeli non-negative. Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur-

Re: [R] Model design

2011-12-16 Thread ONKELINX, Thierry
Dear Alfreda, anova(area_grass) will tell you IF the average grass area is different among areas. If you want to know WHICH areas are different from each other, then you have to do some multiple comparisons. You can use the multcomp package: e.g. library(multcomp) glht(area_grass, linfct = mc

Re: [R] Model design

2011-12-16 Thread ONKELINX, Thierry
2011 at 2:17 PM, ONKELINX, Thierry wrote: > Dear Alfreda, > > anova(area_grass) will tell you IF the average grass area is different among > areas. > > If you want to know WHICH areas are different from each other, then you have > to do some multiple comparisons. You ca

Re: [R] R report generator (for Word)?

2012-01-02 Thread ONKELINX, Thierry
Dear Michael, Our current work flow is to use Sweave and LaTeX. If Word output is needed we convert the LaTeX files to html using htlatex (installed with MikTex). Those html files can be opened with ms word. Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek /

Re: [R] Create variable with AND IF statement

2012-01-02 Thread ONKELINX, Thierry
Dear Richard, You can do this with some nested ifelse statements. Assuming variable2.num has only positive integers and variable1.fac is only 0 or 1 Variable3 <- ifelse(variable1.fac == 0, ifelse(variable2.num == 0, 1, 2), ifelse(variable2.num == 0; 3; 4)) A more fancy solution as.numeric(fac

Re: [R] Histogram: plot by group

2012-01-03 Thread ONKELINX, Thierry
Nameless, http://had.co.nz/ggplot2/geom_histogram.html has a few examples ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium thierry.

<    1   2   3   4   5   6   7   >