Displaying 8 results from an estimated 8 matches for "bootrstrp".
Did you mean:
bootrstrap
2024 Jan 13
2
Strange results : bootrstrp CIs
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,
##########################################
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",
2024 Jan 13
1
Strange results : bootrstrp CIs
? Sat, 13 Jan 2024 20:33:47 +0000 (UTC)
varin sacha via R-help <r-help at r-project.org> ?????:
> 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() picks up the global variables inherited by the
func() closure.
2024 Jan 13
1
Fwd: Strange results : bootrstrp CIs
Sorry, didn't cc this to the list.
-------- Forwarded Message --------
Subject: Re: [R] Strange results : bootrstrp CIs
Date: Sat, 13 Jan 2024 17:37:19 -0500
From: Duncan Murdoch <murdoch.duncan at gmail.com>
To: varin sacha <varinsacha at yahoo.fr>
You can debug things like this by setting options(error = recover). That
will drop into the debugger when the error occurs. Examine t.star, r,
and re...
2024 Jan 14
1
Fwd: Strange results : bootrstrp CIs
On Sat, 13 Jan 2024 17:59:16 -0500
Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
<SNIP>
> My guess is that one of the bootstrap samples had a different
> selection of countries, so factor(Country) had different levels, and
> that would really mess things up.
>
> You'll need to decide how to handle that: If you are trying to
> estimate the coefficient for
2024 Jan 14
1
Fwd: Strange results : bootrstrp CIs
On 13/01/2024 8:58 p.m., Rolf Turner wrote:
> On Sat, 13 Jan 2024 17:59:16 -0500
> Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
>
> <SNIP>
>
>> My guess is that one of the bootstrap samples had a different
>> selection of countries, so factor(Country) had different levels, and
>> that would really mess things up.
>>
>> You'll
2024 Jan 13
1
Strange results : bootrstrp CIs
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 I get an error message (code here below)! So, it still does not work.
Error in t.star[r, ] <-
2024 Jan 14
1
Strange results : bootrstrp CIs
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 = dat[idx,]))
}
B <- boot(e, func, R=1000)
boot.ci(B, index=2, type="perc")
2024 Jan 13
1
Strange results : bootrstrp CIs
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 <- function(data, idx) {
coef(lm(Score~ Time + factor(Country, levels =cc),data=data[idx,]))
}
but lm()