Re: [R] Strange results : bootrstrp CIs

2024-01-13 Thread Rolf Turner
On Sat, 13 Jan 2024 16:54:01 -0800 Bert Gunter wrote: > Well, this would seem to work: > > e <- data.frame(Score = Score > , Country = factor(Country) > , Time = Time) > > ncountry <- nlevels(e$Country) > func= function(dat,idx) { >

Re: [R] Strange results : bootrstrp CIs

2024-01-13 Thread Bert Gunter
Well, this would seem to work: e <- data.frame(Score = Score , Country = factor(Country) , Time = Time) ncountry <- nlevels(e$Country) func= function(dat,idx) { if(length(unique(dat[idx,'Country'])) < ncountry) NA else coef(lm(Score~ Time + Country,data =

Re: [R] Strange results : bootrstrp CIs

2024-01-13 Thread Ben Bolker
It took me a little while to figure this out, but: the problem is that if your resampling leaves out any countries (which is very likely), your model applied to the bootstrapped data will have fewer coefficients than your original model. I tried this: cc <- unique(e$Country) func <-

Re: [R] Strange results : bootrstrp CIs

2024-01-13 Thread varin sacha via R-help
Dear Duncan, Dear Ivan, I really thank you a lot for your response. So, if I correctly understand your answers the problem is coming from this line: coef(lm(Score~ Time + factor(Country)),data=data[idx,]) This line should be: coef(lm(Score~ Time + factor(Country),data=data[idx,])) If yes, now

Re: [R] Strange results : bootrstrp CIs

2024-01-13 Thread Ivan Krylov via R-help
В Sat, 13 Jan 2024 20:33:47 + (UTC) varin sacha via R-help пишет: > coef(lm(Score~ Time + factor(Country)),data=data[idx,]) Wrong place for the data=... argument. You meant to give it to lm(...), but in the end it went to coef(...). Without the data=... argument, the formula passed to lm()

Re: [R] Strange results : bootrstrp CIs

2024-01-13 Thread Duncan Murdoch
On 13/01/2024 3:33 p.m., varin sacha via R-help wrote: Score=c(345,564,467,675,432,346,476,512,567,543,234,435,654,411,356,658,432,345,432,345, 345,456,543,501) Country=c("Italy", "Italy", "Italy", "Turkey", "Turkey", "Turkey", "USA", "USA", "USA", "Korea", "Korea", "Korea", "Portugal",

[R] Strange results : bootrstrp CIs

2024-01-13 Thread varin sacha via R-help
Dear R-experts, Here below, my R code working BUT I get a strange result I was not expecting! Indeed, the 95% percentile bootstrap CIs is (-54.81, -54.81 ). Is anything going wrong? Best, ##