[R] Specify multiple nested random effects in lme with heteroskedastic variance across group

2018-02-20 Thread suraj keshri
I want to fit a random effects model with two separate nested random effects. I can easily do this using the `lmer` package in R. Here's how: model<-lmer(y ~ 1 + x + (1 | oid/gid) + (1 | did/gid), data=data) Here, I'm fitting a random intercept for `oid` nested within `gid` and `did` nested

Re: [R] regex for "[2440810] / www.tinyurl.com/hgaco4fha3"

2018-02-20 Thread Bert Gunter
These are always kind of fun, not least because of the variety of different replies that "work" at least somewhat. Here's mine: > stringa <- "[2440810] / www.tinyurl.com/hgaco4fha3" > sub("^(.+)www\\.(.+)\\.com.+","\\1\\2",stringa) [1] "[2440810] / tinyurl" Note the use of doubled backslashes

Re: [R] regex for "[2440810] / www.tinyurl.com/hgaco4fha3"

2018-02-20 Thread Ulrik Stervbo
Hi Omar, you are almost there but! Your first substitution looks 'www' as the start of the line followed by anything (which then do nothing), so your second substitution removes everything from the first '.' to be found (which is the one after www). What you want to do is x <- "[2440810] /

[R] regex for "[2440810] / www.tinyurl.com/hgaco4fha3"

2018-02-20 Thread Omar André Gonzáles Díaz
Hi, I need help for cleaning this: "[2440810] / www.tinyurl.com/hgaco4fha3" My desired output is: "[2440810] / tinyurl". My attemps: stringa <- "[2440810] / www.tinyurl.com/hgaco4fha3" b <- sub('^www.', '', stringa) #wanted to get rid of "www." part. Until first dot. b <- sub('[.].*', '',

Re: [R] Aggregate over multiple and unequal column length data frames

2018-02-20 Thread Bert Gunter
All columns in a data.frame **must** have the same length. So you cannot do this unless empty values are filled with missings (NA's). -- Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his

Re: [R] deparseDots to get names of all arguments?

2018-02-20 Thread Spencer Graves
On 2018-02-20 20:52, William Dunlap wrote: > Does substitute(...()) do what you want?   That's the key.  Thanks very much.   Spencer Graves > > > myFunc <- function(x, ...) substitute(...()) > > myFunc(y=1/(1:10), x=sin(3:1), z=stop("Oops"), "untagged arg") > $y > 1/(1:10) > > $z >

Re: [R] deparseDots to get names of all arguments?

2018-02-20 Thread William Dunlap via R-help
Does substitute(...()) do what you want? > myFunc <- function(x, ...) substitute(...()) > myFunc(y=1/(1:10), x=sin(3:1), z=stop("Oops"), "untagged arg") $y 1/(1:10) $z stop("Oops") [[3]] [1] "untagged arg" > names(.Last.value) [1] "y" "z" "" Bill Dunlap TIBCO Software wdunlap tibco.com On

[R] Aggregate over multiple and unequal column length data frames

2018-02-20 Thread Ek Esawi
Hi All-- I have generated several 2 column data frames with variable length. The data frames have the same column names and variable types. I was trying to aggregate over the 2nd column for all the date frames, but could not figure out how. I thought i could make them all of equal length then

Re: [R] deparseDots to get names of all arguments?

2018-02-20 Thread Bert Gunter
Duncan et.al: Referring to my previous suggestion for f: > f(log(x),x^2) [1] "log(x)" "x^2" Is this not what you want? Cheers, Bert On Tue, Feb 20, 2018 at 4:00 PM, Duncan Murdoch wrote: > On 20/02/2018 5:47 PM, Rolf Turner wrote: > >> On 21/02/18 11:36, Spencer

Re: [R] deparseDots to get names of all arguments?

2018-02-20 Thread Bert Gunter
If you want to avoid the inefficiency and memory overhead of first constructing the list and work directly on the language, then I think ?match.call is the tool you want. e.g. > f <- function(...){ z <- as.list(match.call())[-1] vapply(z,deparse,"a") } > a <- 1 > b <- 2 > f(a,b) [1]

Re: [R] deparseDots to get names of all arguments?

2018-02-20 Thread Duncan Murdoch
On 20/02/2018 5:47 PM, Rolf Turner wrote: On 21/02/18 11:36, Spencer Graves wrote: Hi, All:   How can I get the names of all the arguments in dots(...)?   I'm able to get the name of the first argument but not the second: deparseDots <- function(...){  

Re: [R] deparseDots to get names of all arguments?

2018-02-20 Thread Rolf Turner
On 21/02/18 11:36, Spencer Graves wrote: Hi, All:   How can I get the names of all the arguments in dots(...)?   I'm able to get the name of the first argument but not the second: deparseDots <- function(...){   deparse(substitute(...)) } a <- 1 b <- 2 deparseDots(a, b) [1] "a"

[R] deparseDots to get names of all arguments?

2018-02-20 Thread Spencer Graves
Hi, All:   How can I get the names of all the arguments in dots(...)?   I'm able to get the name of the first argument but not the second: deparseDots <- function(...){   deparse(substitute(...)) } a <- 1 b <- 2 deparseDots(a, b) [1] "a"   I'd like to get c('a', 'b').  

Re: [R] question regarding the AICcmodavg package

2018-02-20 Thread Cade, Brian
Do not model average the regression coefficients. This makes no sense (see Cade 2015. Model averaging and muddled multimodel inferences). And, no there is no reasonable way to model average regression coefficients ala Burnham and Anderson approach when some of your models include interactions

[R] question regarding the AICcmodavg package

2018-02-20 Thread Hannah van Noort
Dear moderator, If possible I would like to send in the following question for R-help: I am analyzing a small data set using PGLS with phylogenetic uncertainty taken into account and thereby including 100 potential phylogenetic tree scenarios. I've managed to run models on all of the different

Re: [R] Take the maximum of every 12 columns

2018-02-20 Thread Henrik Bengtsson
It looks like OP uses a data.frame, so in order to use matrixStats (I'm the author) one would have to pay the price to coerce to a matrix before using matrixStats::rowMaxs(). However, if it is that the original data could equally well live in a matrix, then matrixStats should be computational

Re: [R] "Within" model in plm package: is the reported R-squared correct?

2018-02-20 Thread Bert Gunter
Generally speaking, statistical questions are O/T here, but sometimes they intersect with on-topic R programming issues and do get responses. So if you do not get a response here, try a statistics forum, like stats.stackexchange.com . Cheers, Bert Bert Gunter "The trouble with having an open

[R] "Within" model in plm package: is the reported R-squared correct?

2018-02-20 Thread Dung Nguyen
Hi everyone, I am doing panel data analysis using the 'plm' package. However, I have noticed that the plm() function reports a different value of R-squared from the R-squared of the lm() function with time-demeaned data. To be clear, I have tried to compute the within model both manually (run an

Re: [R] Take the maximum of every 12 columns

2018-02-20 Thread Ista Zahn
On Tue, Feb 20, 2018 at 11:58 AM, Bert Gunter wrote: > Ista, et. al: efficiency? > (Note: I needed to correct my previous post: do.call() is required for > pmax() over the data frame) > > > x <- data.frame(matrix(runif(12e6), ncol=12)) > > > system.time(r1 <-

Re: [R] Take the maximum of every 12 columns

2018-02-20 Thread Bert Gunter
Sorry, previous code should be: > x <- data.frame(matrix(runif(12e6), ncol=12)) > system.time(r1 <- do.call(pmax,x)) user system elapsed 0.049 0.000 0.049 > system.time(r2 <- apply(x,1,max)) user system elapsed 2.162 0.045 2.207 > identical(r1,r2) [1] TRUE Bert Gunter "The

Re: [R] Take the maximum of every 12 columns

2018-02-20 Thread Bert Gunter
Ista, et. al: efficiency? (Note: I needed to correct my previous post: do.call() is required for pmax() over the data frame) > x <- data.frame(matrix(runif(12e6), ncol=12)) > system.time(r1 <- do.call(pmax,x)) user system elapsed 0.049 0.000 0.049 > identical(r1,r2) [1] FALSE >

Re: [R] Take the maximum of every 12 columns

2018-02-20 Thread Miluji Sb
This is what I was looking for. Thank you everyone! Sincerely, Milu Mail priva di virus. www.avast.com

Re: [R] Take the maximum of every 12 columns

2018-02-20 Thread Bert Gunter
Do you want the max of all the data in all 12 columns -- 1 number -- or the parallel max of the 12 columns -- a vector of length the number of rows. In the first case, max(df[,1:12]) will do (R uses 1-based indexing,not 0-based) ; in the second case, pmax(df[, 1:12]) will do. If either of

Re: [R] Take the maximum of every 12 columns

2018-02-20 Thread Ista Zahn
Hi Milu, byapply(df, 12, function(x) apply(x, 1, max)) You might also be interested in the matrixStats package. Best, Ista On Tue, Feb 20, 2018 at 9:55 AM, Miluji Sb wrote: > Dear all, > > I have monthly data in wide format, I am only providing data (at the bottom > of

Re: [R] Take the maximum of every 12 columns

2018-02-20 Thread Miluji Sb
Thank you for your kind replies. Maybe I was not clear with my question (I apologize) or I did not understand... I would like to take the max for X0...X11 and X12...X24 in my dataset. When I use pmax with the function byapply as in byapply(df, 12, pmax) I get back a list which I cannot convert

Re: [R] Take the maximum of every 12 columns

2018-02-20 Thread Bert Gunter
Don't do this (sorry Thierry)! max() already does this -- see ?max > x <- data.frame(a =rnorm(10), b = rnorm(10)) > max(x) [1] 1.799644 > max(sapply(x,max)) [1] 1.799644 Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into

Re: [R] Take the maximum of every 12 columns

2018-02-20 Thread Thierry Onkelinx
The maximum over twelve columns is the maximum of the twelve maxima of each of the columns. single_col_max <- apply(x, 2, max) twelve_col_max <- apply( matrix(single_col_max, nrow = 12), 2, max ) ir. Thierry Onkelinx Statisticus / Statistician Vlaamse Overheid / Government of Flanders

Re: [R] Take the maximum of every 12 columns

2018-02-20 Thread Bert Gunter
?pmax Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, Feb 20, 2018 at 6:55 AM, Miluji Sb wrote: > Dear all, > > I have

[R] Take the maximum of every 12 columns

2018-02-20 Thread Miluji Sb
Dear all, I have monthly data in wide format, I am only providing data (at the bottom of the email) for the first 24 columns but I have 2880 columns in total. I would like to take max of every 12 columns. I have taken the mean of every 12 columns with the following code: byapply <- function(x,

Re: [R] JGR not installed. Attempting to install from CRAN...

2018-02-20 Thread Jenny Coetzee
thanks Loris you are bering so helpful! So, i have done what you explained, but the RDS package that runs “using or through” R is now just closing each time i open it. I have googled and seen that i need to to the following: Tips: The recent updates to the Apple Mac OS (Sierra and High

Re: [R] JGR not installed. Attempting to install from CRAN...

2018-02-20 Thread Loris Bennett
Jenny Coetzee writes: > thanks Loris > > you are bering so helpful! > > So, i have done what you explained, but the RDS package that runs > “using or through” R is now just closing each time i open it. I have > googled and seen that i need to to the following: > > Tips: The

Re: [R] JGR not installed. Attempting to install from CRAN...

2018-02-20 Thread Michael Dewey
Dear Jenny From your email address I would have thought one of the two South African ones would be best. In the unlikely event of your chosen mirror not being up-to-date, try another one. Michael On 20/02/2018 07:55, Jenny Coetzee wrote: Loris, thank you thank you so much!!! do you know

Re: [R] JGR not installed. Attempting to install from CRAN...

2018-02-20 Thread Jenny Coetzee
Loris, thank you thank you so much!!! do you know which CRAN mirror i select? There are loads - all related to various countries.. so appreciate the help Jenny Jenny Coetzee (PhD Candidate) Head of Prevention in Key Populations & Head of the Soweto Sex Worker Project Perinatal HIV Research

Re: [R] JGR not installed. Attempting to install from CRAN...

2018-02-20 Thread Loris Bennett
Hi Jenny, Jenny Coetzee writes: > Loris, thank you thank you so much!!! > > do you know which CRAN mirror i select? There are loads - all related to > various countries.. > > so appreciate the help It shouldn't really matter, although I'd choose one that is