Description Usage Arguments Examples
The function cpr_coef
is used to fit the following Polynomial Regression model with the parameter constraints and returns the estimated coefficients β's:
for i = 1,2,...,n
,
Y_i = β_0 + ∑_{j=1}^p { β_j * (X_i) ^ j } + ε_i
ε_i ~ N(0,σ^2)
where coefficient β_j = β_{j-1} / j for j = 2,...,p
, and predictor X_i = i / n
1 | cpr_coef(p,y)
|
p |
A positive integer indicates the polynomial degree. Larger or equal to 2. NA is not allowed |
y |
A numeric vector that contains the true outcomes. NA is not allowed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | p = 5
y = c(1,3,3,3,4,5,3,2,-1)
cpr_res = cpr_coef(p, y)
cpr_res$coefficients
# Estimate
# (intercept) 3.452393951
# b1 -1.100167971
# b2 -0.550083985
# b3 -0.183361328
# b4 -0.045840332
# b5 -0.009168066
cpr_res$residuals
# [1] 2.32310324 0.17861859 0.01715603 -0.16327333 -1.36488198 -2.59012461 -0.84171677 -0.12265344 2.56377227
cpr_res$fitted.values
# [1] 3.323103 3.178619 3.017156 2.836727 2.635118 2.409875 2.158283 1.877347 1.563772
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.