Re: [R] [R-sig-ME] lmer error: number of observations <= number of random effects

2024-05-06 Thread Thierry Onkelinx via R-help
Dear Srinidhi, You are trying to fit 1 random intercept and 2 random slopes per individual, while you have at most 3 observations per individual. You simply don't have enough data to fit the random slopes. Reduce the random part to (1|ID). Best regards, Thierry ir. Thierry Onkelinx Statisticus

Re: [R] GAM with binary predictors

2023-02-16 Thread Thierry Onkelinx via R-help
Dear Sacha, use glm() in this case. I'd rather code the covariable as TRUE / FALSE or as a factor. Best regards, ir. Thierry Onkelinx Statisticus / Statistician Vlaamse Overheid / Government of Flanders INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND FOREST Team

Re: [R] getting to a point where packages are installed and "ready to use", without unnecessarily reinstalling packages

2022-10-25 Thread Thierry Onkelinx via R-help
Dear Kelly, Have a look at the renv package (https://CRAN.R-project.org/package=renv). Once setup, your code reduces to renv::restore() Best regards, ir. Thierry Onkelinx Statisticus / Statistician Vlaamse Overheid / Government of Flanders INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH

Re: [R] inconsistencies between HLM and clmm results for the signs for the coefficients

2022-10-21 Thread Thierry Onkelinx via R-help
Dear Debbie, Have a look at the vignette of the ordinal package. Look for the equation that defines \eta. And note the minus sign associated with \beta. You'll need to find the equation used in HLM and compare it with the equation from ordinal. Best regards, ir. Thierry Onkelinx Statisticus /

Re: [R] Live Online Training for High School Teachers and Students

2021-11-04 Thread Thierry Onkelinx via R-help
Dear Tracy, Maybe a workshop of Data Carpentry (https://datacarpentry.org/) might be relevant. Best regards, ir. Thierry Onkelinx Statisticus / Statistician Vlaamse Overheid / Government of Flanders INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND FOREST Team

Re: [R] ggplot error of "`data` must be a data frame, or other object coercible by `fortify()`, not an S3 object with class rxlsx"

2021-08-26 Thread Thierry Onkelinx via R-help
eth is not a dataframe but of the class rxlsx. You'll need to convert eth into a dataframe. ir. Thierry Onkelinx Statisticus / Statistician Vlaamse Overheid / Government of Flanders INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND FOREST Team Biometrie & Kwaliteitszorg

Re: [R] Secondary y axis in ggplot2: did not respond when change its y-axis value

2021-01-12 Thread Thierry Onkelinx via R-help
The second y-axis in ggplot2 is only intended to relabel an axis with a fixed transformation. E.g. one axis in degree Celcius and one in Kelvin, km and miles, ... It does not rescale the variables. It looks like you want to display two variables with unrelated units on the same y-axis. That is

Re: [R] Need guidance on summarizing time data

2020-11-30 Thread Thierry Onkelinx via R-help
Dear Bruce, I think this should be straightforward with tidyverse. If not please provide a small reproducible data set with dput(). library(tidyverse) count(Active, Time) count(Active, Date, Time) Best regards, ir. Thierry Onkelinx Statisticus / Statistician Vlaamse Overheid / Government of

Re: [R] backslash in xtable (generate latex code from R)

2020-11-06 Thread Thierry Onkelinx via R-help
You could use kable() from the knitr package. kable(mytable, format = "latex", escape = FALSE) \begin{tabular}{l} \hline $\beta_0$\\ \hline aa\\ \hline bb\\ \hline cc$\alpha_1$\\ \hline \end{tabular} ir. Thierry Onkelinx Statisticus / Statistician Vlaamse Overheid / Government of Flanders

Re: [R] Reorganize the data (dplyr or other packages?)

2020-08-17 Thread Thierry Onkelinx via R-help
> melt(x,id.vars="date",measure.vars=c("down","uc","up"),variable.name > ="direction",value.name="percentage") > > HTH, > Eric > > > On Mon, Aug 17, 2020 at 10:49 AM Thierry Onkelinx via R-help < > r-help@r-project.org>

Re: [R] Reorganize the data (dplyr or other packages?)

2020-08-17 Thread Thierry Onkelinx via R-help
You are looking for tidyr::pivot_longer() Best regards, ir. Thierry Onkelinx Statisticus / Statistician Vlaamse Overheid / Government of Flanders INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND FOREST Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality

Re: [R] lme4 - Mixed Model question

2020-07-13 Thread Thierry Onkelinx via R-help
Dear Axel, A few quick remarks. 1) This question is more suitable for r-sig-mixed-models. 2) A mixed model needs much more than two groups. If you have only a few groups, consider a glm with group interactions. 3) Setting the value of a covariate to zero for a set of observations has the same

Re: [R] unique scale color ggplot2

2020-07-07 Thread Thierry Onkelinx via R-help
hn Tukey /// <https://www.inbo.be> Op di 7 jul. 2020 om 18:42 schreef Rasmus Liland : > On 2020-07-07 12:44 +0200, Thierry Onkelinx via R-help wrote: > > Op di 7 jul. 2020 om 12:02 schreef Catalin Roibu >: > > > >

Re: [R] unique scale color ggplot2

2020-07-07 Thread Thierry Onkelinx via R-help
Dear Catalin, use scale_fill_gradient() and set fixed limits ggplot(df1, aes(x=as.factor(spei), y=as.factor(month), fill = cut(cor, zCuts))) + geom_tile() + scale_fill_gradient(limits = c(-0.7, 0.7)) Best regards, ir. Thierry Onkelinx Statisticus / Statistician Vlaamse Overheid /

Re: [R] Rstudio does not run on ubuntu 20

2020-06-15 Thread Thierry Onkelinx via R-help
Dear Luigi, This is rather an RStudio problem than an R problem. I suggest contacting RStudio or their community help forum at https://community.rstudio.com/ Best regards, ir. Thierry Onkelinx Statisticus / Statistician Vlaamse Overheid / Government of Flanders INSTITUUT VOOR NATUUR- EN

Re: [R] Package renv and Rscript

2020-04-14 Thread Thierry Onkelinx via R-help
Dear Ben, I think that you first need to go to your project and then start Rscript from that location. renv() needs to pick up the .Renviron file located at the root of your project. Best regards, ir. Thierry Onkelinx Statisticus / Statistician Vlaamse Overheid / Government of Flanders

Re: [R] to create a new variable based on values in other variables

2020-04-07 Thread Thierry Onkelinx via R-help
Dear Ding, It seems that you are looking for the ifelse() function. Clear use of pmax() and pmin() reduces the number of if statements. m1 <- c(12, 23, 22, 23) m2 <- c(23, 23, 3, 5) Ravg <- ifelse( pmax(m1, m2) == 23, pmin(m1, m2), (m1 + m2) / 2 ) Best regards, ir. Thierry Onkelinx

Re: [R] stats::power.t.test error

2019-10-04 Thread Thierry Onkelinx via R-help
Think about this. What is the null hypothesis? What is the alternative? What are their distributions? What is the probability that you get a value from the alternative when the null hypothesis holds and vice versa? Then think again about the relevance of your alternative hypothesis. You'll get a

[R] mutate() error

2019-09-05 Thread Thierry Onkelinx via R-help
Dear all, I'm using this in a function inside a package. The code works fine when I run it directly. df %>% mutate(!!id_column := row_number()) When I run the function I get this error: Error in mutate(., `:=`(!!id_column, row_number())) : argument "mutate" is missing, with no default df

Re: [R] linear mixed model required for the U.S. FDA

2019-08-19 Thread Thierry Onkelinx via R-help
Dear Helmut, The mixed models list is more suitable for this kind of question. I'm forwarding it to that list. Please send any follow-up to that list instead of the general R help list. If I understand correctly, you'll need a different variance term for both treatments (the within subject for T

Re: [R] Simulate I x J contingency tables using correlation coefficient using bivariate normal distribution

2019-08-19 Thread Thierry Onkelinx via R-help
Dear Sripriya, Step 1. generate random values from a multivariate normal distribution Step 2. convert the random values into probabilities Step 3. convert the probabilities into values from the target distribution library(mvtnorm) n <- 1e3 correl <- 0.9 lambda <- c(10, 50) sigma <-

Re: [R] Debugging Rmarkdown

2019-04-18 Thread Thierry Onkelinx via R-help
Dear Patrick, This is not easy to debug without a reprex I would check the content of zzz and wide.i in the loop str(wide.i) zzz <- rbind(zzz, wide.i) str(zzz) Note that the Rmd always runs in a clean environment. This might explain the difference Best regards, ir. Thierry Onkelinx

Re: [R] Why does R do this?

2019-01-08 Thread Thierry Onkelinx via R-help
Dear Nick, The best solution is not to use which() but directy use the logical test. This will work in case the condition is always FALSE and which() returns a integer(0). And it is much faster too. z <- y > 3 y[!z] library(microbenchmark) microbenchmark( y[!y > 3], y[-which(y > 3)] ) Best

Re: [R] R code for if-then-do code blocks

2018-12-17 Thread Thierry Onkelinx via R-help
Dear Paul, R's power is that is works vectorised. Unlike SAS which is rowbased. Using R in a SAS way will lead to very slow code. Your examples can be written vectorised d1 %>% rownames_to_column("ID") %>% mutate( test1 = ifelse(gender == "f" & workshop == 1, 7, 0), test2 =

Re: [R] Request for aid in first R script

2018-11-19 Thread Thierry Onkelinx via R-help
Dear Kepler, Yes, R can do this all. But this is is to help you when you get stuck, not to do all the work for you... You are asking basic stuff, so any introduction book on R should contain sufficient information to get you going. So please do read on of those first. Best regards, ir. Thierry