Showing posts with label Residual-standard. Show all posts
Showing posts with label Residual-standard. Show all posts

Wednesday, November 27, 2019

Residual standard

Residual standard error

> set.seed(1234)
> x = seq(0, 10)
>
> y = 3 + x + 4 * x ^ 2 + rnorm(11, 0, 20)
>
> plot(x, y, ylim = c(-300, 400), cex = 2, pch = 20)
> fit = lm(y ~ x + I(x ^ 2))
>
> fit_perf = lm(y ~ x + I(x ^ 2) + I(x ^ 3) + I(x ^ 4) + I(x ^ 5) + I(x ^ 6)
+               + I(x ^ 7) + I(x ^ 8) + I(x ^ 9) + I(x ^ 10))
>
> summary(fit_perf)

Call:
lm(formula = y ~ x + I(x^2) + I(x^3) + I(x^4) + I(x^5) + I(x^6) +
    I(x^7) + I(x^8) + I(x^9) + I(x^10))

Residuals:
ALL 11 residuals are 0: no residual degrees of freedom!

Coefficients:
              Estimate Std. Error t value Pr(>|t|)
(Intercept) -2.114e+01         NA      NA       NA
x           -1.918e+03         NA      NA       NA
I(x^2)       4.969e+03         NA      NA       NA
I(x^3)      -4.932e+03         NA      NA       NA
I(x^4)       2.581e+03         NA      NA       NA
I(x^5)      -8.035e+02         NA      NA       NA
I(x^6)       1.570e+02         NA      NA       NA
I(x^7)      -1.947e+01         NA      NA       NA
I(x^8)       1.490e+00         NA      NA       NA
I(x^9)      -6.424e-02         NA      NA       NA
I(x^10)      1.195e-03         NA      NA       NA

Residual standard error: NaN on 0 degrees of freedom
Multiple R-squared:      1, Adjusted R-squared:    NaN
F-statistic:   NaN on 10 and 0 DF,  p-value: NA
Rprogrammingstatistics

> xplot = seq(0, 10, by = 0.1)
> lines(xplot, predict(fit, newdata = data.frame(x = xplot)),
+       col = "dodgerblue", lwd = 2, lty = 1)
>
> lines(xplot, predict(fit_perf, newdata = data.frame(x = xplot)),
+       col = "darkorange", lwd = 2, lty = 2)

Black-Scholes formula-R

 Black-Scholes formula-R > BlackScholes <- function(TypeFlag = c("c", "p"), S, X, Time, r, b, sigma) { TypeFla...