LenaH
August 27, 2020, 5:57pm
1
Hi,
I'm afraid boot() doesn't want to become friends with me.
I tried to boot a very simple regression and I did it exactly as told by the Quick-R: Bootstrapping site. But it won't calculate the bias and the standard error...
My script looks as followed:
TPfunction <- function(formula, data, coefficients) {
d <- data[coefficients, ]
fitTP <- lm(formula, data = d)
return(coef(fitTP))
}
boot_JSTP <- boot(data = data_JS2, statistic = TPfunction, R = 1000, formula = JS.All2 ~ TP.All2)
boot.ci(boot_JSTP,
conf = .95,
type = "bca",
replace = T, index = 2)
And the output like that:
> boot_JSTP
ORDINARY NONPARAMETRIC BOOTSTRAP
Call:
boot(data = data_JS2, statistic = TPfunction, R = 1000, formula = JS.All2 ~
TP.All2)
Bootstrap Statistics :
original bias std. error
t1* 5.784360 0 0
t2* -0.174887 0 0
Does anybody know what I miss?
That does look strange.
I think it might depend on what data_JS2 is.
What is your output when you do:
TPfunction <- function(formula, data, coefficients) {
d <- data[coefficients, ]
fitTP <- lm(formula, data = d)
return(coef(fitTP))
}
data_JS2 <-data.frame(
JS.All2 = c(rep(0,500),rep(12,500)),
TP.All2 =c(rep(0,450),rep(6,550))
)
group_by_all(data_JS2)%>%summarise(n=n())
boot_JSTP <- boot(data = data_JS2, statistic = TPfunction, R = 1000, formula = JS.All2 ~ TP.All2)
boot_JSTP
LenaH
August 27, 2020, 6:55pm
3
Hi,
thanks for the reply.
With your script my output looks like this:
> TPfunction <- function(formula, data, coefficients) {
+ d <- data[coefficients, ]
+ fitTP <- lm(formula, data = d)
+ return(coef(fitTP))
+ }
> data_JS2 <-data.frame(
+ JS.All2 = c(rep(0,500),rep(12,500)),
+ TP.All2 =c(rep(0,450),rep(6,550))
+ )
> group_by_all(data_JS2)%>%summarise(n=n())
Fehler in group_by_all(data_JS2) %>% summarise(n = n()) :
konnte Funktion "%>%" nicht finden
> boot_JSTP <- boot(data = data_JS2, statistic = TPfunction, R = 1000, formula = JS.All2 ~ TP.All2)
> boot_JSTP
ORDINARY NONPARAMETRIC BOOTSTRAP
Call:
boot(data = data_JS2, statistic = TPfunction, R = 1000, formula = JS.All2 ~
TP.All2)
Bootstrap Statistics :
original bias std. error
t1* -2.049203e-13 2.003240e-13 7.424014e-14
t2* 1.818182e+00 3.931745e-04 2.406952e-02
I used data_JS2 for another bootstrap. Its a data frame of 6 variables and 327 observations.
ok. with my made up data_JS2, you get the same results as me.
In principle can you share data_JS2 ?
I think we only need the two variables you use.
library(dplyr)
dput(data_JS2 %>% select(JS.All2 , TP.All2))
and copy and paste the results
LenaH
August 27, 2020, 7:02pm
5
That worked
I created a new data frame with only the two needed varibales and it works well.
Thank you so much!!!
system
Closed
September 3, 2020, 7:02pm
6
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.