[R] [EXTERNAL] Re: Very strange behavior of 'rep'
Izmirlian, Grant (NIH/NCI) [E]
|zm|r||g @end|ng |rom m@||@n|h@gov
Thu Aug 15 21:00:32 CEST 2024
Ok � to be fair, it looks like I need to load everything and reproduce exactly as its occuring. I suspect its a weird memory hole in one of the loaded packages.
Here � this should do it.
"%,%" <- paste0
"factorial.design" <-
function(...)
{
m <- match.call()
cc <- m
cc[[1]] <- as.name("c")
arg.vals <- eval(cc, sys.parent())
n.args <- length(arg.vals)
n.l <- 0
n.r <- n.args-1
fwd.cpd <- c(1, cumprod(arg.vals))
rev.cpd <- c(cumprod(arg.vals[n.args:2])[(n.args-1):1],1)
"%,%" <- paste0
main.call <- as.call(expression(cbind))
for(k in 1:n.args)
{
arg.k <- eval(m[[1+k]], sys.parent())
rep.call <- as.call(expression(rep))
rep.call$x <- 1:arg.k
if(n.l>0) rep.call$times <- fwd.cpd[k]
if(n.r>0) rep.call$each <- rev.cpd[k]
main.call[["x" %,% k]] <- rep.call
n.l <- n.l + 1
n.r <- n.r - 1
}
eval(main.call)
}
add.zeros <-
function(x,B)
{
do.one <- function(x,B)
{
delta <- floor(logb(B, 10)) - floor(logb(x, 10))
z <- ""
if(delta > 0) z <- paste(rep("0", delta), collapse="")
z%,%x
}
if(length(x)==1) ans <- do.one(x,B)
if(length(x)>1) ans <- sapply(x, FUN=do.one, B=B)
ans
}
library(lme4)
rho.ICC <- 0.5
s2.b <- 0.5*rho.ICC/(1-rho.ICC)
s2.e <- 0.5
delta <- 0.27
n.per.grp.lst <- (264/2*(1-450/9900*(5:0)))
## I will different values of 'h' and at these contrasts as well as flat
## I want to compare the AUC approach with just the test of the main effects constant arm coefficient
tt.seq <- c(0,3,6,12,18)
n.tt <- length(tt.seq)
cntr <- c(0.5,1,1,1,0.5)
## (delta1 + 2*delta2 + 2*delta3 + 2*delta4 + delta5)/2 = 0.27
## delta1 + 2*delta2 + 2*delta3 + 2*delta4 + delta5 = 2*0.27
## (delta1 + 2*delta2 + 2*delta3 + 2*delta4 + delta5)/8 = 2*0.27/8 = 0.27/4
H <- 0.08+0.005*(0:6)
shapes <- list(INC= (-floor(n.tt/2)):floor(n.tt/2),
DEC= floor(n.tt/2):(-floor(n.tt/2)),
FLT= rep(0,n.tt),
PLT= c(-floor(n.tt/2):0,rep(floor(n.tt/2)+1, n.tt-floor(n.tt/2)-1)))
trnds <- names(shapes)
delta0.j <- rep(5, n.tt)
n.n.lst <- length(n.per.grp.lst)
n.trnds <- length(trnds)
n.H <- length(H)
## We're swarming over conditions. It works like this. This is the
## full list of conditions as a factorial design list. You have to
## determine the total number of conditions and then set up that many
## directories in the swarm folder
conds <- factorial.design(n.n.lst, n.trnds, n.H)
## currently with n.n.lst=6, n.trnds=4, n.H=7 that gives
## length(conds)=6x4x7=168
## then one copy of this file sits in each of the subdirectories.
## Parameters for this run are determined by getting the subdirectory
## number and then pulling the parameter indices from that element
## in the factorial design.
node <- 29
n.per.grp <- n.per.grp.lst[conds[node, 1]]
trnd <- trnds[conds[node, 2]]
h <- H[conds[node, 3]]
delta.j <- delta + h*shapes[[trnd]]
## covariates:
ID.i <- c(outer(rep(1:n.per.grp,each=n.tt),c(0,n.per.grp),FUN="+"))
arm.i <- rep(0:1, each=n.per.grp*n.tt)
length(arm.i)
________________________________
From: Rui Barradas <ruipbarradas using sapo.pt>
Sent: Thursday, August 15, 2024 2:51 PM
To: Izmirlian, Grant (NIH/NCI) [E] <izmirlig using mail.nih.gov>; r-help using r-project.org <r-help using r-project.org>
Subject: [EXTERNAL] Re: [R] Very strange behavior of 'rep'
�s 19:39 de 15/08/2024, Izmirlian, Grant (NIH/NCI) [E] via R-help escreveu:
> \n<<SEND AS PLAIN TEXT!>>\n\n \n<<
> This is very weird. I was running a swarm job on the cluster and it bombed
> only for n.per.grp=108, not for the other values. Even though
> n.per.grp*n.tt is 540, so that the length of the call to 'rep'
> should be 1080, I'm getting a vector of length 1078.
> n.per.grp <- 108
> n.tt <- 5
> n.per.grp*n.tt
> length(rep(0:1, each=n.per.grp*n.tt))
> length(rep(0:1, each=108*5))
>>> \n<<Grant Izmirlian grant.izmirlian at nih dot gov>>\n\n\n\n
> --please do not edit the information below--
>
> R Version:
> platform = x86_64-pc-linux-gnu
> arch = x86_64
> os = linux-gnu
> system = x86_64, linux-gnu
> status =
> major = 4
> minor = 4.1
> year = 2024
> month = 06
> day = 14
> svn rev = 86737
> language = R
> version.string = R version 4.4.1 (2024-06-14)
> nickname = Race for Your Life
>
> Locale:
> LC_CTYPE=C.UTF-8;LC_NUMERIC=C;LC_TIME=C.UTF-8;LC_COLLATE=C.UTF-8;LC_MONETARY=C.UTF-8;LC_MESSAGES=C.UTF-8;LC_PAPER=C.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C.UTF-8;LC_IDENTIFICATION=C
>
> Search Path:
> .GlobalEnv, package:lme4, package:Matrix, package:stats,
> package:graphics, package:grDevices, package:utils, package:datasets,
> package:showtext, package:showtextdb, package:sysfonts,
> package:methods, Autoloads, package:base
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C02%7Cizmirlig%40mail.nih.gov%7C4e8285dc4d984018750208dcbd5b9586%7C14b77578977342d58507251ca2dc2b06%7C0%7C0%7C638593448252923470%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=ERmJnji4cVBWI36ESgUcMPY5E52l%2FTrb%2BF4s%2F1gGSVg%3D&reserved=0<https://stat.ethz.ch/mailman/listinfo/r-help>
> PLEASE do read the posting guide https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=05%7C02%7Cizmirlig%40mail.nih.gov%7C4e8285dc4d984018750208dcbd5b9586%7C14b77578977342d58507251ca2dc2b06%7C0%7C0%7C638593448252932192%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=UXsJuXSKTRbYPwcPnTwKQeARyE6AksBsXwNq4NICJGw%3D&reserved=0<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
Hello,
I cannot reproduce this behavior.
n.per.grp <- 108
n.tt <- 5
n.per.grp*n.tt
#> [1] 540
length(rep(0:1, each = n.per.grp*n.tt))
#> [1] 1080
length(rep(0:1, each = 108*5))
#> [1] 1080
But my version of R and my OS are different.
(I don't see how the error in the OP can be related to R version or OS.)
R.version
#> _
#> platform x86_64-w64-mingw32
#> arch x86_64
#> os mingw32
#> crt ucrt
#> system x86_64, mingw32
#> status
#> major 4
#> minor 4.1
#> year 2024
#> month 06
#> day 14
#> svn rev 86737
#> language R
#> version.string R version 4.4.1 (2024-06-14 ucrt)
#> nickname Race for Your Life
Hope this helps,
Rui Barradas
--
Este e-mail foi analisado pelo software antiv�rus AVG para verificar a presen�a de v�rus.
https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.avg.com%2F&data=05%7C02%7Cizmirlig%40mail.nih.gov%7C4e8285dc4d984018750208dcbd5b9586%7C14b77578977342d58507251ca2dc2b06%7C0%7C0%7C638593448252937455%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=wlmoS3S2xNYFV9E%2FlVjvKw1XGhSQjx3KoQjgOBwNp4I%3D&reserved=0<http://www.avg.com/>
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and are confident the content is safe.
[[alternative HTML version deleted]]
More information about the R-help
mailing list