Skip to content

Commit 8f1089e

Browse files
committed
Correct a bug in 'nlsJack' when the model was fitting using weighted least squares (issue #5)
1 parent 5230ff6 commit 8f1089e

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
importFrom("stats", "coef", "confint", "df.residual", "fitted", "formula",
33
"pnorm", "ppoints", "predict", "profile", "qf", "qnorm",
44
"qqline", "qqnorm", "qt", "quantile", "resid", "residuals",
5-
"runif", "sd", "shapiro.test", "update", "vcov")
5+
"runif", "sd", "shapiro.test", "update", "vcov", "weights")
66
importFrom("grDevices", "terrain.colors")
77
importFrom("graphics", "abline", "boxplot", "contour", "hist", "image",
88
"layout", "lines", "par", "plot", "points", "text")

R/nlsJack.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
np <- length(coef(nls))
1010

1111
l1 <- lapply(1:nl, function(z){
12-
nls2 <- update(nls, data=data[-z,], start=as.list(coef(nls)));
13-
return(list(coef=coef(nls2), sigma=summary(nls2)$sigma, rss=sum(residuals(nls2)^2), dfb=abs(coef(nls2)-coef(nls))/(summary(nls)$parameters[,2])))
12+
if(!is.null(weights(nls))) {
13+
nls2 <- update(nls, data=data[-z,], weights= weights(nls)[-z], start=as.list(coef(nls)))
14+
} else {
15+
nls2 <- update(nls, data=data[-z,], start=as.list(coef(nls)))
16+
}
17+
return(list(coef=coef(nls2), sigma=summary(nls2)$sigma, rss=sum(residuals(nls2)^2), dfb=abs(coef(nls2)-coef(nls))/(summary(nls)$parameters[,2])))
1418
})
15-
19+
1620
tabjack <- t(sapply(l1, function(z) z$coef))
1721
rsejack <- sapply(l1, function(z) z$sigma)
1822
rssjack <- sapply(l1, function(z) z$rss)

0 commit comments

Comments
 (0)