0% found this document useful (0 votes)
7 views5 pages

Estatística Não-Paramétrica em R

Uploaded by

hpmmarcondes
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

Estatística Não-Paramétrica em R

Uploaded by

hpmmarcondes
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Trabalho No4.

CE313 - Estatística Não-Paramétrica

Rafael Alisson Schipiura

05 de agosto, 2024

1
data <- [Link](age = c(5.2, 8.8, 10.5, 10.6, 10.4, 1.8, 12.7, 15.6,
5.8, 1.9, 2.2, 4.8, 7.9, 5.2, 0.9, 11.8, 7.9, 1.5, 10.6, 8.5, 11.1,
12.8, 11.3, 1, 14.5, 11.9, 8.1, 13.8, 15.5, 9.8, 11, 12.4, 11.1, 5.1,
4.8, 4.2, 6.9, 13.2, 9.9, 12.5, 13.2, 8.9, 10.8), peptide = c(4.8,
4.1, 5.2, 5.5, 5, 3.4, 3.4, 4.9, 5.6, 3.7, 3.9, 4.5, 4.8, 4.9, 3, 4.6,
4.8, 5.5, 4.5, 5.3, 4.7, 6.6, 5.1, 3.9, 5.7, 5.1, 5.2, 3.7, 4.9, 4.8,
4.4, 5.2, 5.1, 4.6, 3.9, 5.1, 5.1, 6, 4.9, 4.1, 4.6, 4.9, 5.1))
n <- nrow(data)
data <- data[order(data$age), ]
dividir <- 4
for (parte in 1:dividir - 1) {
print(kable(t(data[((parte * n/dividir) + 1):((parte + 1) * n/dividir),
]), [Link] = NULL))
}
age 0.9 1.0 1.5 1.8 1.9 2.2 4.2 4.8 4.8 5.1
peptide 3.0 3.9 5.5 3.4 3.7 3.9 5.1 4.5 3.9 4.6
age 5.2 5.2 5.8 6.9 7.9 7.9 8.1 8.5 8.8 8.9
peptide 4.8 4.9 5.6 5.1 4.8 4.8 5.2 5.3 4.1 4.9
age 9.9 10.4 10.5 10.6 10.6 10.8 11.0 11.1 11.1 11.3
peptide 4.9 5.0 5.2 5.5 4.5 5.1 4.4 4.7 5.1 5.1
age 11.9 12.4 12.5 12.7 12.8 13.2 13.2 13.8 14.5 15.5
peptide 5.1 5.2 4.1 3.4 6.6 6.0 4.6 3.7 5.7 4.9

1
(a) Regressão kernel
mod0 <- npregbw(peptide ~ age, data = data, regtype = "lc")
plot(mod0, col = "red", lwd = 3, [Link] = "bootstrap", xlim = range(data$age),
ylim = range(data$peptide))
points(peptide ~ age, data = data, pch = 19, col = "blue")
6.0
peptide

5.0
4.0
3.0

5 10 15

age
summary(mod0)

##
## Regression Data (43 observations, 1 variable(s)):
##
## Regression Type: Local-Constant
## Bandwidth Selection Method: Least Squares Cross-Validation
## Formula: peptide ~ age
## Bandwidth Type: Fixed
## Objective Function Value: 0.4631 (achieved on multistart 1)
##
## Exp. Var. Name: age Bandwidth: 2.609 Scale Factor: 1.333
##
## Continuous Kernel Type: Second-Order Gaussian
## No. Continuous Explanatory Vars.: 1
## Estimation Time: 0.002 seconds
predict(mod0)$R2

## [1] 0.2293

2
(b) Regressão linear local
mod1 <- npregbw(peptide ~ age, data = data, regtype = "ll")
plot(mod1, col = "red", lwd = 3, [Link] = "bootstrap", xlim = range(data$age),
ylim = range(data$peptide))
points(peptide ~ age, data = data, pch = 19, col = "blue")
6.0
peptide

5.0
4.0
3.0

5 10 15

age
summary(mod1)

##
## Regression Data (43 observations, 1 variable(s)):
##
## Regression Type: Local-Linear
## Bandwidth Selection Method: Least Squares Cross-Validation
## Formula: peptide ~ age
## Bandwidth Type: Fixed
## Objective Function Value: 0.472 (achieved on multistart 1)
##
## Exp. Var. Name: age Bandwidth: 4.54 Scale Factor: 2.321
##
## Continuous Kernel Type: Second-Order Gaussian
## No. Continuous Explanatory Vars.: 1
## Estimation Time: 0.003 seconds
predict(mod1)$R2

## [1] 0.2067

(c) Regressão spline


simulador <- function(dados) {
n <- nrow(dados)
[Link] <- sample(1:n, size = n, replace = TRUE)
return(dados[[Link], ])

3
}
m <- 300
B <- 2000
[Link] <- list(age = seq(from = min(data$age), to = max(data$age), [Link] = m))
[Link] <- function(dados) {
suppressWarnings(ajuste <- [Link](x = dados[, 1], y = dados[,
2], cv = TRUE))
return(predict(ajuste, x = [Link]$age)$y)
}
[Link] <- function(dados) {
[Link] <- [Link](dados)
[Link] <- replicate(B, [Link](simulador(dados)))
lower <- numeric(m)
upper <- numeric(m)
for (i in 1:m) {
sorted <- sort([Link][i, ])
lower[i] <- sorted[0.025 * B]
upper[i] <- sorted[0.975 * B]
}
return(list(main = [Link], lower = lower, upper = upper))
}
ci <- [Link](data)
plot(x = [Link]$age, y = ci$main, type = "l", col = "red", lwd = 3,
ylim = range(data$peptide), xlab = "age", ylab = "peptide")
lines(x = [Link]$age, y = ci$upper, lty = 2)
lines(x = [Link]$age, y = ci$lower, lty = 2)
points(peptide ~ age, data = data, pch = 19, col = "blue")
6.0
peptide

5.0
4.0
3.0

5 10 15

age

4
(d) Regressão quantílica
mod3 <- rqss(peptide ~ qss(age, lambda = 0.6), data = data)
summary(mod3)

## Formula:
## peptide ~ qss(age, lambda = 0.6)
##
## Parametric coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.510 0.718 4.89 0.000021 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Approximate significance of qss terms:
## EDF Lambda Penalty F value Pr(>F)
## age 5 0.6 0.798 1.54 0.2
##
## Quantile Fidelity at tau = 0.5 is 9.05074
## Effective Degrees of Freedom = 7 Sample Size = 43
fit <- predict(mod3, [Link], interval = "confidence")
plot(peptide ~ age, data = data, pch = 19, col = "blue")
lines(x = [Link]$age, y = fit[, "yhat"], lwd = 3, col = "red")
lines(x = [Link]$age, y = fit[, "ylower"], lty = 2)
lines(x = [Link]$age, y = fit[, "yupper"], lty = 2)
6.0
peptide

5.0
4.0
3.0

5 10 15

age

Common questions

Powered by AI

The division and regression methods used in the document suggest a way to infer variability among subgroups within the dataset. By dividing the data into ordered segments based on age, and then applying local-constant and local-linear regression, it becomes possible to observe patterns or deviations that might exist within those subgroups. The varied R-squared values from these regression methods (0.2293 for local-constant and 0.2067 for local-linear) and different bandwidths highlight variability in how peptide concentrations relate to age, with some segments demonstrating different levels of predictability and trends . Moreover, the use of spline regression further allows for capturing nuanced variability by fitting smooth curves across the age spectrum, revealing changes that simpler models might miss . This approach underscores the presence of diverse patterns in the data, necessitating comprehensive regression strategies to unearth the underlying trends.

Local-constant regression and spline regression differ significantly in their estimation strategies and flexibility. Local-constant regression estimates the value of the dependent variable by considering a weighted average of the neighboring data points using a fixed kernel. This simple strategy results in predictions that are constant within each neighborhood, providing limited flexibility in capturing local variations if the actual relationship is not constant . In contrast, spline regression introduces more flexibility by fitting a smooth curve through all available data points. Spline regression uses piecewise polynomials, which can change in shape to better conform to the data's structure, especially when employing methods like cross-validation to set smoothing parameters. This allows spline regression to model complex patterns and provide a much better fit along with associated confidence intervals, as demonstrated by bootstrap resampling in the document . Thus, while local-constant regression is simpler and computationally less intensive, spline regression offers enhanced adaptability to detailed data structures.

Non-parametric techniques are utilized in the document because they offer flexibility without assuming a specific functional form for the relationship between the variables. Unlike parametric methods, which limit analysis to predefined equations like linear or polynomial models, non-parametric techniques can model complex patterns and capture subtle features in data. This flexibility is particularly useful when dealing with datasets where the underlying distribution is unknown or not easily describable by traditional parametric forms. Thus, non-parametric methods can provide a more accurate representation of the underlying data structure without imposing restrictive assumptions .

Bootstrapping is necessary in the context of non-parametric regression in the document to provide a more robust estimate of uncertainty and enhance the reliability of the statistical inference. Since non-parametric methods do not assume a specific distribution and parameter estimation relies entirely on the data, bootstrapping allows for the assessment of variability by resampling with replacement. By repeatedly generating simulated samples, the approach leads to more accurate confidence intervals for predictions, as evident in the spline regression where bootstrapping is used to construct confidence intervals, showing upper and lower bounds for the estimated smooth curve . This is particularly important in non-parametric contexts where traditional distributional assumptions do not hold, ensuring that the results are valid across the range of potential data variations.

Kernel regression, as applied in the document, employs a local-constant regression type, which suggests that it uses a fixed function or kernel to estimate the regression relationship across different data points. This method, characterized by a bandwidth selection via least squares cross-validation, aims to smooth the observed data by considering a neighborhood around each point without altering the function's form across the dataset. In contrast, the local-linear regression approach still uses a kernel-based smoothing technique but fits a linear model within each local neighborhood, allowing for linear variation within these local zones. This generally results in a more flexible and potentially less biased estimate than the local-constant model when the true relationship between variables is not flat. Specifically, local-constant regression is less responsive to changes in the data form compared to local-linear, which accommodates linear trends within segments of data .

Quantile regression functions by estimating the conditional median or other quantiles of the response variable, providing a more comprehensive analysis than mean-based methods, such as least squares regression. This method is beneficial as it allows for the modeling of the impact of variables at different points in the distribution, addressing potential issues with heteroscedasticity and skewed distributions. The document demonstrates this by forming a regression model that accommodates different tau (quantile) levels, allowing for insights into the behavior at these quantiles rather than just the mean. Advantages include robustness to outliers and the ability to capture the breadth of the distribution, offering a fuller picture of the relationship between variables .

In the spline regression model from the document, confidence intervals are constructed using a combination of bootstrapping and spline estimation. The process begins by fitting a smooth spline to the original dataset, then performing bootstrap resampling 2000 times to create a distribution of spline estimates. For each resampling iteration, a spline is fitted, and these estimates are used to derive the percentiles representing the confidence intervals. Specifically, the sorted bootstrap estimates provide the upper and lower bounds of the 95% confidence interval by identifying the 2.5th and 97.5th percentiles. These intervals are plotted alongside the main spline estimate, visually representing the uncertainty in the model's predictions across the age range .

The non-parametric spline regression method utilizes a smoothing spline approach, which fits a smooth curve through the data points. This method is robust as it applies a form of cross-validation to determine the optimal amount of smoothing, balancing the trade-off between fidelity to the data and the smoothness of the curve. In the document, the robustness is further enhanced by using bootstrap resampling to generate confidence intervals, which increases the method's reliability by simulating numerous sample datasets (in this case, 2000 resamplings) and assessing the variability across them . This approach ensures that the estimator is not overly sensitive to fluctuations and the results are reliable even with variability in input data.

The quality of fit in kernel regression methods, as described in the document, is evaluated using the R-squared value, which indicates the proportion of variability in the dependent variable that is predictable from the independent variable. For instance, the R-squared value for the kernel regression with local-constant type is 0.2293, suggesting that approximately 22.93% of the variance in peptide concentration can be accounted for by age. This measure provides a quantitative assessment of the fit quality, highlighting the extent to which the model captures the observed data variability .

Cross-validation in bandwidth selection plays a crucial role by optimizing the balance between bias and variance in regression models. Its significance lies in its ability to estimate the model's predictive performance by dividing the data into subsets, using some for training and others for validation, and then evaluating the error. In the context of the document, least squares cross-validation is employed to select bandwidths for the kernel regression models. By doing so, it ensures that the chosen bandwidths provide the best generalization of the model to new data, avoiding overfitting to the idiosyncrasies of the sample dataset while still maintaining enough flexibility to accurately capture the data's underlying structure .

You might also like