| Title: | Fuzzy Logistic Regression |
|---|---|
| Description: | Fits logistic regression models in which the binary response is represented by a triangular fuzzy number rather than an exact crisp label, allowing uncertainty in class membership to be encoded directly in the outcome. Model parameters are estimated using the Fuzzy Least Squares approach of Diamond (1988) <doi:10.1016/0020-0255(88)90047-3>, following the integrated fuzzy logistic regression method of Yapici Pehlivan and Sahin (2018) <https://dergipark.org.tr/en/pub/jssa/issue/37877/437725>. Provides fitting, prediction, classification, cross-validation, and diagnostic plotting methods, along with tools for comparing model behaviour across different assumed levels of label uncertainty. |
| Authors: | Md Faruk Hasan [aut, cre], Azizur Rahman [aut] |
| Maintainer: | Md Faruk Hasan <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.1 |
| Built: | 2026-10-11 13:03:02 UTC |
| Source: | https://github.com/cran/FuzzyLogit |
A dataset containing measurements from fine needle aspirates (FNA) of
breast masses, used to classify tumours as benign or malignant. This is
a cleaned version of the UCI Breast Cancer Wisconsin dataset with 16
rows containing missing values (in the BareNuclei column)
removed.
data(breast_cancer)data(breast_cancer)
A data frame with 683 rows and 10 columns:
Clump thickness, integer 1-10.
Uniformity of cell size, integer 1-10.
Uniformity of cell shape, integer 1-10.
Marginal adhesion, integer 1-10.
Single epithelial cell size, integer 1-10.
Bare nuclei, integer 1-10.
Bland chromatin, integer 1-10.
Normal nucleoli, integer 1-10.
Mitoses, integer 1-10.
Binary outcome: 0 = Benign (444 cases), 1 = Malignant (239 cases).
The original dataset contains 699 observations and 11 columns
(including a sample ID column). The ID column has been removed, 16 rows
with missing values in BareNuclei have been dropped, and the
class variable (originally coded 2 = benign, 4 = malignant) has been
recoded to Outcome (0 = benign, 1 = malignant).
UCI Machine Learning Repository. https://archive.ics.uci.edu/ml/datasets/Breast+Cancer+Wisconsin+(Original)
Wolberg, W. H. and Mangasarian, O. L. (1990). Multisurface method of pattern separation for medical diagnosis applied to breast cytology. Proceedings of the National Academy of Sciences, 87, 9193-9196.
data(breast_cancer) head(breast_cancer) table(breast_cancer$Outcome) model <- fuzzy_logit( Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, n_alpha = 100 ) summary(model)data(breast_cancer) head(breast_cancer) table(breast_cancer$Outcome) model <- fuzzy_logit( Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, n_alpha = 100 ) summary(model)
This function extracts the row names (case names) from the model frame.
case.names(object, ...)case.names(object, ...)
object |
A fuzzy_logit object |
... |
Additional arguments |
Character vector of case names
Classifies observations as belonging to class 0 or class 1 using a
fitted fuzzy_logit model, builds a confusion matrix against the
observed outcomes, and computes a set of performance metrics.
classify is a generic function; classify.fuzzy_logit is
the method used for objects of class "fuzzy_logit".
classify(object, ...) ## S3 method for class 'fuzzy_logit' classify( object, newdata = NULL, threshold = 0.5, type = c("crisp", "fuzzy"), metrics = c("accuracy", "sensitivity", "specificity", "precision", "recall", "f1", "auc", "kappa"), plot = FALSE, ... ) ## S3 method for class 'classify.fuzzy_logit' print(x, digits = 4, ...) ## S3 method for class 'classify.fuzzy_logit' summary(object, ...)classify(object, ...) ## S3 method for class 'fuzzy_logit' classify( object, newdata = NULL, threshold = 0.5, type = c("crisp", "fuzzy"), metrics = c("accuracy", "sensitivity", "specificity", "precision", "recall", "f1", "auc", "kappa"), plot = FALSE, ... ) ## S3 method for class 'classify.fuzzy_logit' print(x, digits = 4, ...) ## S3 method for class 'classify.fuzzy_logit' summary(object, ...)
object |
An object of class |
... |
Further arguments passed to or from other methods. |
newdata |
An optional data frame of new observations to classify,
which must also contain the true outcome column so a confusion matrix
can be built. If |
threshold |
Numeric value in (0, 1) used as the probability
cutoff for assigning class 1. An observation is classified as 1 if
its predicted probability is greater than or equal to
|
type |
Character string. |
metrics |
Character vector specifying which performance metrics to
compute. Available options are |
plot |
Logical. If |
x |
An object of class |
digits |
Integer. Number of decimal places to display. Default is 4. |
An object of class "classify.fuzzy_logit", a list
containing predictions (a data frame of predicted
probabilities/classes and, if available, observed values),
confusion_matrix, metrics (a named numeric vector of
the requested performance metrics), threshold, type,
and the fitted model.
No return value, called for its side effect of printing the
classification results, confusion matrix, and performance metrics
to the console. Invisibly returns x.
No return value, called for its side effect of printing
detailed classification statistics (TP, TN, FP, FN counts) to the
console. Invisibly returns object.
fuzzy_logit, predict.fuzzy_logit,
cv.fuzzy_logit
data(breast_cancer) model <- fuzzy_logit(Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, n_alpha = 100) ## Classify at the default threshold cls <- classify(model, threshold = 0.5, type = "crisp") print(cls) summary(cls) ## Lower the threshold to increase sensitivity cls2 <- classify(model, threshold = 0.3) cls2$metrics["sensitivity"]data(breast_cancer) model <- fuzzy_logit(Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, n_alpha = 100) ## Classify at the default threshold cls <- classify(model, threshold = 0.5, type = "crisp") print(cls) summary(cls) ## Lower the threshold to increase sensitivity cls2 <- classify(model, threshold = 0.3) cls2$metrics["sensitivity"]
Extract coefficients from fuzzy_logit model
## S3 method for class 'fuzzy_logit' coef(object, type = c("a", "s", "both"), ...)## S3 method for class 'fuzzy_logit' coef(object, type = c("a", "s", "both"), ...)
object |
A fuzzy_logit object |
type |
Type of coefficient to extract |
... |
Additional arguments |
If type = "a" or type = "s", a named numeric
vector of coefficients. If type = "both", a list with two
named numeric vectors, a (centre coefficients) and s
(spread parameters).
This function extracts the central tendency coefficients from a fuzzy_logit model.
## S3 method for class 'fuzzy_logit' coefficients(object, ...)## S3 method for class 'fuzzy_logit' coefficients(object, ...)
object |
A fuzzy_logit object |
... |
Additional arguments |
Named numeric vector of centre coefficients.
Takes a named list of cv.fuzzy_logit results and displays their
performance metrics side by side in a single comparison table. Useful
for comparing how different fuzzy membership settings, or different
model specifications, affect generalisation performance.
compare_cv_results(cv_list)compare_cv_results(cv_list)
cv_list |
A named list containing at least two objects of class
|
A data frame of class comparing performance metrics across models, with one row per model/setting and one column per metric. Also printed to the console.
data(breast_cancer) cv_low <- cv.fuzzy_logit( formula = Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, K = 5, mu_0 = c(0.01, 0.03, 0.05), mu_1 = c(0.95, 0.97, 0.99), n_alpha = 100, seed = 42, verbose = FALSE ) cv_high <- cv.fuzzy_logit( formula = Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, K = 5, mu_0 = c(0.10, 0.20, 0.30), mu_1 = c(0.70, 0.80, 0.90), n_alpha = 100, seed = 42, verbose = FALSE ) compare_cv_results(list("Low fuzziness" = cv_low, "High fuzziness" = cv_high))data(breast_cancer) cv_low <- cv.fuzzy_logit( formula = Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, K = 5, mu_0 = c(0.01, 0.03, 0.05), mu_1 = c(0.95, 0.97, 0.99), n_alpha = 100, seed = 42, verbose = FALSE ) cv_high <- cv.fuzzy_logit( formula = Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, K = 5, mu_0 = c(0.10, 0.20, 0.30), mu_1 = c(0.70, 0.80, 0.90), n_alpha = 100, seed = 42, verbose = FALSE ) compare_cv_results(list("Low fuzziness" = cv_low, "High fuzziness" = cv_high))
Fits multiple fuzzy logistic regression models with different membership function specifications and compares their results.
compare_fuzzy_models(formula, data, mu_list = NULL, verbose = TRUE, ...)compare_fuzzy_models(formula, data, mu_list = NULL, verbose = TRUE, ...)
formula |
A formula object specifying the model |
data |
A data frame containing the variables |
mu_list |
A named list of mu specifications, where each element is a list containing mu_0 and mu_1. If NULL, uses default comparisons. |
verbose |
Logical. If |
... |
Additional arguments passed to fuzzy_logit |
A list of class "fuzzy_logit_comparison" containing:
models |
List of fitted fuzzy_logit models |
comparison_table |
Data frame comparing coefficients across models |
spread_table |
Data frame comparing spread parameters across models |
fit_statistics |
Data frame with AIC, BIC, and other fit statistics |
data(breast_cancer) # Compare three levels of uncertainty comparison <- compare_fuzzy_models( Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, mu_list = list( low = list(mu_0 = c(0.01, 0.03, 0.05), mu_1 = c(0.95, 0.97, 0.99)), medium = list(mu_0 = c(0.05, 0.10, 0.15), mu_1 = c(0.85, 0.90, 0.95)), high = list(mu_0 = c(0.10, 0.20, 0.30), mu_1 = c(0.70, 0.80, 0.90)) ), n_alpha = 100 ) print(comparison)data(breast_cancer) # Compare three levels of uncertainty comparison <- compare_fuzzy_models( Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, mu_list = list( low = list(mu_0 = c(0.01, 0.03, 0.05), mu_1 = c(0.95, 0.97, 0.99)), medium = list(mu_0 = c(0.05, 0.10, 0.15), mu_1 = c(0.85, 0.90, 0.95)), high = list(mu_0 = c(0.10, 0.20, 0.30), mu_1 = c(0.70, 0.80, 0.90)) ), n_alpha = 100 ) print(comparison)
Confidence intervals for fuzzy_logit model parameters
## S3 method for class 'fuzzy_logit' confint(object, parm = NULL, level = 0.95, ...)## S3 method for class 'fuzzy_logit' confint(object, parm = NULL, level = 0.95, ...)
object |
A fuzzy_logit object |
parm |
Parameters to include (default: all) |
level |
Confidence level (default: 0.95) |
... |
Additional arguments |
A matrix with columns giving the lower and upper confidence limits for each requested parameter, computed as the centre coefficient plus/minus a t-based margin using the spread parameter as an approximate standard error.
Cross-Validation for Fuzzy Logistic Regression
cv.fuzzy_logit( formula, data, K = 10, mu_0 = c(0.01, 0.03, 0.05), mu_1 = c(0.95, 0.97, 0.99), n_alpha = NULL, stratified = TRUE, seed = NULL, metrics = c("accuracy", "sensitivity", "specificity", "precision", "f1", "auc"), threshold = 0.5, verbose = TRUE, ... )cv.fuzzy_logit( formula, data, K = 10, mu_0 = c(0.01, 0.03, 0.05), mu_1 = c(0.95, 0.97, 0.99), n_alpha = NULL, stratified = TRUE, seed = NULL, metrics = c("accuracy", "sensitivity", "specificity", "precision", "f1", "auc"), threshold = 0.5, verbose = TRUE, ... )
formula |
A formula object |
data |
A data frame |
K |
Number of folds |
mu_0 |
Fuzzy membership for class 0 |
mu_1 |
Fuzzy membership for class 1 |
n_alpha |
Number of alpha-cuts |
stratified |
Whether to use stratified sampling |
seed |
Random seed |
metrics |
Metrics to compute |
threshold |
Classification threshold |
verbose |
Whether to print progress |
... |
Additional arguments |
An object of class "cv.fuzzy_logit", a list containing:
metrics (a data frame of performance metrics per fold),
mean_metrics and sd_metrics (named numeric vectors of
metrics averaged and their standard deviation across folds),
predictions (a data frame of out-of-fold predictions),
confusion_matrix (the overall confusion matrix pooled across
folds), and the fold assignments, formula, and settings used.
Deviance for fuzzy_logit model
## S3 method for class 'fuzzy_logit' deviance(object, ...)## S3 method for class 'fuzzy_logit' deviance(object, ...)
object |
A fuzzy_logit object |
... |
Additional arguments |
A single numeric value: the sum of squared deviance residuals.
Extract residual degrees of freedom
## S3 method for class 'fuzzy_logit' df.residual(object, ...)## S3 method for class 'fuzzy_logit' df.residual(object, ...)
object |
A fuzzy_logit object |
... |
Additional arguments |
A single integer: the number of observations minus the number of estimated coefficients (including the intercept).
Extract fitted values from fuzzy_logit model
## S3 method for class 'fuzzy_logit' fitted(object, type = c("link", "response"), ...)## S3 method for class 'fuzzy_logit' fitted(object, type = c("link", "response"), ...)
object |
A fuzzy_logit object |
type |
Type of fitted values |
... |
Additional arguments |
A numeric vector of fitted values, one per observation used in
fitting the model. On the "link" scale these are log-odds; on
the "response" scale these are probabilities in [0, 1].
Extract formula from fuzzy_logit model
## S3 method for class 'fuzzy_logit' formula(x, ...)## S3 method for class 'fuzzy_logit' formula(x, ...)
x |
A fuzzy_logit object |
... |
Additional arguments |
An object of class "formula": the model formula used to
fit the object.
Fits a fuzzy logistic regression model using triangular fuzzy numbers for the response variable. Users can customize the fuzzy membership values to control the degree of fuzziness in the model.
fuzzy_logit( formula, data, mu_0 = c(0.01, 0.03, 0.05), mu_1 = c(0.95, 0.97, 0.99), n_alpha = NULL, na.action = na.omit, subset = NULL, contrasts = NULL, ... )fuzzy_logit( formula, data, mu_0 = c(0.01, 0.03, 0.05), mu_1 = c(0.95, 0.97, 0.99), n_alpha = NULL, na.action = na.omit, subset = NULL, contrasts = NULL, ... )
formula |
A formula object specifying the model, e.g., y ~ x1 + x2 + ... Can include transformations, interactions, and factor variables. |
data |
A data frame containing the variables in the model |
mu_0 |
A numeric vector of length 3 specifying the triangular fuzzy number for the negative class (y = 0) as c(left, mode, right). Default is c(0.01, 0.03, 0.05) representing low uncertainty. **Users can modify these values to change the fuzziness level.** |
mu_1 |
A numeric vector of length 3 specifying the triangular fuzzy number for the positive class (y = 1) as c(left, mode, right). Default is c(0.95, 0.97, 0.99) representing low uncertainty. **Users can modify these values to change the fuzziness level.** |
n_alpha |
Integer specifying the number of alpha-cut levels for numerical integration. Higher values give more accurate integration but slower computation. Default is the number of rows in the data (can be computationally expensive for large datasets). |
na.action |
A function which indicates what should happen when the data contain NAs. Default is na.omit. |
subset |
An optional vector specifying a subset of observations to be used |
contrasts |
An optional list for factor contrasts |
... |
Additional arguments (currently unused) |
The fuzzy membership values control the degree of uncertainty in class assignment. Narrower triangles (e.g., mu_0 = c(0.01, 0.03, 0.05)) represent low fuzziness, closer to crisp logistic regression. Wider triangles (e.g., mu_0 = c(0.10, 0.25, 0.40)) represent high fuzziness and more uncertainty in classification.
An object of class "fuzzy_logit" containing model results
data(breast_cancer) # Basic usage with default fuzzy membership model1 <- fuzzy_logit(Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, n_alpha = 100) summary(model1) # Custom fuzzy membership (moderate uncertainty) model2 <- fuzzy_logit( Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, mu_0 = c(0.05, 0.10, 0.15), mu_1 = c(0.85, 0.90, 0.95), n_alpha = 100 )data(breast_cancer) # Basic usage with default fuzzy membership model1 <- fuzzy_logit(Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, n_alpha = 100) summary(model1) # Custom fuzzy membership (moderate uncertainty) model2 <- fuzzy_logit( Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, mu_0 = c(0.05, 0.10, 0.15), mu_1 = c(0.85, 0.90, 0.95), n_alpha = 100 )
Check if object is a fuzzy_logit model
is.fuzzy_logit(x)is.fuzzy_logit(x)
x |
An object to check |
Logical value indicating if object is of class fuzzy_logit
Computes an approximate log-likelihood assuming normal errors. Note: This is an approximation as fuzzy regression does not have a standard likelihood function.
## S3 method for class 'fuzzy_logit' logLik(object, ...)## S3 method for class 'fuzzy_logit' logLik(object, ...)
object |
A fuzzy_logit object |
... |
Additional arguments |
An object of class "logLik" with the approximate
log-likelihood value and attributes "df" (number of estimated
parameters) and "nobs" (number of observations).
Extract model frame from fuzzy_logit model
## S3 method for class 'fuzzy_logit' model.frame(formula, ...)## S3 method for class 'fuzzy_logit' model.frame(formula, ...)
formula |
A fuzzy_logit object |
... |
Additional arguments |
A data frame containing the response and predictor variables
used in fitting the model (i.e. the original data after applying
na.action and any subset).
Extract model matrix from fuzzy_logit model
## S3 method for class 'fuzzy_logit' model.matrix(object, ...)## S3 method for class 'fuzzy_logit' model.matrix(object, ...)
object |
A fuzzy_logit object |
... |
Additional arguments |
A numeric matrix: the design matrix used in estimation, with one row per observation and one column per model parameter (including the intercept).
Extract number of observations from fuzzy_logit model
## S3 method for class 'fuzzy_logit' nobs(object, ...)## S3 method for class 'fuzzy_logit' nobs(object, ...)
object |
A fuzzy_logit object |
... |
Additional arguments |
A single integer: the number of observations used in fitting the model (after any rows with missing values have been removed).
Groups observations into bins by fitted probability and plots the
average residual within each bin, together with an approximate 95%
confidence band. Equivalent to plot(model, which = 2), provided
as a standalone named function for convenience.
plot_binned_residuals(model)plot_binned_residuals(model)
model |
A fuzzy_logit object |
This plot is often the most informative of the four diagnostic plots. Bin averages that stay within the grey confidence band indicate the model is reasonably well calibrated. Bins outside the band point to specific probability ranges where the model is systematically over- or under-predicting.
A ggplot object, printed as a side effect and returned invisibly.
plot.fuzzy_logit, plot_pearson_residuals,
plot_scale_location, plot_leverage
data(breast_cancer) model <- fuzzy_logit(Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, n_alpha = 100) plot_binned_residuals(model)data(breast_cancer) model <- fuzzy_logit(Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, n_alpha = 100) plot_binned_residuals(model)
Creates a visualization of the triangular fuzzy membership functions for both classes to help users understand the effect of mu parameters.
plot_fuzzy_membership( mu_0 = c(0.01, 0.03, 0.05), mu_1 = c(0.95, 0.97, 0.99), main = "Fuzzy Membership Functions" )plot_fuzzy_membership( mu_0 = c(0.01, 0.03, 0.05), mu_1 = c(0.95, 0.97, 0.99), main = "Fuzzy Membership Functions" )
mu_0 |
Triangular fuzzy number for class 0: c(left, mode, right) |
mu_1 |
Triangular fuzzy number for class 1: c(left, mode, right) |
main |
Title for the plot |
A ggplot object showing the fuzzy membership functions
# Default membership functions plot_fuzzy_membership() # Custom membership functions with more uncertainty plot_fuzzy_membership( mu_0 = c(0.05, 0.15, 0.25), mu_1 = c(0.75, 0.85, 0.95) )# Default membership functions plot_fuzzy_membership() # Custom membership functions with more uncertainty plot_fuzzy_membership( mu_0 = c(0.05, 0.15, 0.25), mu_1 = c(0.75, 0.85, 0.95) )
Plots deviance residuals against leverage (the diagonal of the hat
matrix), highlighting influential observations whose Cook's distance
exceeds 4/n. Equivalent to plot(model, which = 4), provided
as a standalone named function for convenience.
plot_leverage(model)plot_leverage(model)
model |
A fuzzy_logit object |
Observations highlighted in red have a Cook's distance greater than 4/n, a common rule-of-thumb threshold for flagging influential points. High leverage combined with a large residual indicates an observation that may be disproportionately affecting the fitted coefficients and is worth inspecting individually.
A ggplot object, printed as a side effect and returned invisibly.
plot.fuzzy_logit, plot_pearson_residuals,
plot_binned_residuals, plot_scale_location
data(breast_cancer) model <- fuzzy_logit(Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, n_alpha = 100) plot_leverage(model)data(breast_cancer) model <- fuzzy_logit(Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, n_alpha = 100) plot_leverage(model)
Produces a single diagnostic plot of Pearson residuals against fitted
probabilities for a fitted fuzzy_logit object. Equivalent to
plot(model, which = 1), provided as a standalone named function
for convenience.
plot_pearson_residuals(model)plot_pearson_residuals(model)
model |
A fuzzy_logit object |
Points should scatter without any strong systematic curve. The gentle arch shape typically seen in this plot is a normal artefact of binary outcomes and is not on its own evidence of poor fit. Look instead for isolated extreme outliers (beyond roughly +/- 4).
A ggplot object, printed as a side effect and returned invisibly.
plot.fuzzy_logit, plot_binned_residuals,
plot_scale_location, plot_leverage
data(breast_cancer) model <- fuzzy_logit(Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, n_alpha = 100) plot_pearson_residuals(model)data(breast_cancer) model <- fuzzy_logit(Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, n_alpha = 100) plot_pearson_residuals(model)
Plots the absolute value of the Pearson residuals against fitted
probabilities, used to check for non-constant residual variance
(heteroscedasticity). Equivalent to plot(model, which = 3),
provided as a standalone named function for convenience.
plot_scale_location(model)plot_scale_location(model)
model |
A fuzzy_logit object |
For binary outcomes, the variance of the Pearson residual is approximately p(1-p), which is maximised at p = 0.5. This produces an inverted-U shape in the smooth trend line, which is expected and not a sign of model misspecification.
A ggplot object, printed as a side effect and returned invisibly.
plot.fuzzy_logit, plot_pearson_residuals,
plot_binned_residuals, plot_leverage
data(breast_cancer) model <- fuzzy_logit(Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, n_alpha = 100) plot_scale_location(model)data(breast_cancer) model <- fuzzy_logit(Outcome ~ ClumpThickness + UniformCellSize + BareNuclei, data = breast_cancer, n_alpha = 100) plot_scale_location(model)
Produces up to four diagnostic plots for a fitted fuzzy_logit model.
Plots can be shown all at once or individually using the which
argument or the dedicated single-plot functions.
## S3 method for class 'fuzzy_logit' plot(x, which = 1:4, ...)## S3 method for class 'fuzzy_logit' plot(x, which = 1:4, ...)
x |
A fuzzy_logit object |
which |
Integer vector specifying which plots to produce. 1 = Pearson Residuals vs Fitted, 2 = Binned Residual Plot, 3 = Scale-Location, 4 = Residuals vs Leverage. Default is 1:4 (all plots). |
... |
Additional arguments (currently unused) |
Diagnostic plots are adapted from classical logistic regression for convenience. They are approximate tools for model checking and are not theoretically derived from the fuzzy least squares estimation framework.
Invisibly returns a named list of ggplot objects:
pearson, binned, scale_location, leverage.
Use p <- plot(model) then p$pearson to access individually.
data(breast_cancer) model <- fuzzy_logit(Outcome ~ ClumpThickness + BareNuclei, data = breast_cancer, n_alpha = 100) # All four plots plot(model) # Individual plots using which plot(model, which = 1) plot(model, which = 2) plot(model, which = 3) plot(model, which = 4) # Individual plots using named functions plot_pearson_residuals(model) plot_binned_residuals(model) plot_scale_location(model) plot_leverage(model) # Save a single plot to a temporary file p <- plot(model) ggplot2::ggsave(file.path(tempdir(), "pearson.png"), p$pearson, width = 7, height = 5)data(breast_cancer) model <- fuzzy_logit(Outcome ~ ClumpThickness + BareNuclei, data = breast_cancer, n_alpha = 100) # All four plots plot(model) # Individual plots using which plot(model, which = 1) plot(model, which = 2) plot(model, which = 3) plot(model, which = 4) # Individual plots using named functions plot_pearson_residuals(model) plot_binned_residuals(model) plot_scale_location(model) plot_leverage(model) # Save a single plot to a temporary file p <- plot(model) ggplot2::ggsave(file.path(tempdir(), "pearson.png"), p$pearson, width = 7, height = 5)
Predict method for fuzzy_logit models
## S3 method for class 'fuzzy_logit' predict( object, newdata = NULL, type = c("link", "response"), se.fit = FALSE, ... )## S3 method for class 'fuzzy_logit' predict( object, newdata = NULL, type = c("link", "response"), se.fit = FALSE, ... )
object |
A fitted fuzzy_logit object |
newdata |
Optional data frame for predictions |
type |
Type of prediction |
se.fit |
Whether to return standard errors |
... |
Additional arguments |
If se.fit = FALSE, a numeric vector of predictions.
If se.fit = TRUE, a list with components fit (numeric
vector of predicted values) and se.fit (numeric vector of
corresponding approximate standard errors).
Print Cross-Validation Results
## S3 method for class 'cv.fuzzy_logit' print(x, digits = 4, ...)## S3 method for class 'cv.fuzzy_logit' print(x, digits = 4, ...)
x |
An object of class |
digits |
Integer. Number of decimal places to display. Default is 4. |
... |
Further arguments passed to or from other methods (currently unused). |
No return value, called for its side effect of printing the
mean (+/- SD) performance metrics and pooled confusion matrix to the
console. Invisibly returns x.
Print method for fuzzy_logit objects
## S3 method for class 'fuzzy_logit' print(x, digits = 4, ...)## S3 method for class 'fuzzy_logit' print(x, digits = 4, ...)
x |
A fuzzy_logit object |
digits |
Number of digits to display |
... |
Additional arguments |
No return value, called for its side effect of printing the
model call, coefficients, and degrees of freedom to the console.
Invisibly returns x.
Print method for fuzzy_logit_comparison
## S3 method for class 'fuzzy_logit_comparison' print(x, digits = 4, ...)## S3 method for class 'fuzzy_logit_comparison' print(x, digits = 4, ...)
x |
A fuzzy_logit_comparison object |
digits |
Number of digits to display |
... |
Additional arguments |
No return value, called for its side effect of printing the
fit statistics and pivoted coefficient/spread comparison tables to
the console. Invisibly returns x.
Print method for summary.fuzzy_logit objects
## S3 method for class 'summary.fuzzy_logit' print(x, digits = 4, signif.stars = TRUE, ...)## S3 method for class 'summary.fuzzy_logit' print(x, digits = 4, signif.stars = TRUE, ...)
x |
A summary.fuzzy_logit object |
digits |
Number of digits to display |
signif.stars |
Logical, whether to show significance stars |
... |
Additional arguments |
No return value, called for its side effect of printing the
formatted model summary to the console. Invisibly returns x.
Extract residuals from fuzzy_logit model
## S3 method for class 'fuzzy_logit' residuals(object, type = c("response", "deviance", "pearson"), ...)## S3 method for class 'fuzzy_logit' residuals(object, type = c("response", "deviance", "pearson"), ...)
object |
A fuzzy_logit object |
type |
Type of residuals |
... |
Additional arguments |
A numeric vector of residuals, one per observation used in
fitting the model. The scale depends on type: "response"
residuals are on the log-odds scale, "pearson" residuals are
standardised, and "deviance" residuals are signed square roots
of each observation's deviance contribution.
Summarise Cross-Validation Results
## S3 method for class 'cv.fuzzy_logit' summary(object, ...)## S3 method for class 'cv.fuzzy_logit' summary(object, ...)
object |
An object of class |
... |
Further arguments passed to or from other methods (currently unused). |
No return value, called for its side effect of printing the
overall results plus per-fold performance metrics to the console.
Invisibly returns object.
Summary method for fuzzy_logit objects
## S3 method for class 'fuzzy_logit' summary(object, digits = 4, ...)## S3 method for class 'fuzzy_logit' summary(object, digits = 4, ...)
object |
A fuzzy_logit object |
digits |
Number of digits to display |
... |
Additional arguments |
An object of class "summary.fuzzy_logit", a list
containing the model call, a coefficient table (coefficients)
with centre estimate, spread, approximate SE, t-value, p-value, and
significance code for each variable, the residual standard error,
degrees of freedom, number of observations, and the fuzzy membership
parameters used to fit the model.
Extract terms from fuzzy_logit model
## S3 method for class 'fuzzy_logit' terms(x, ...)## S3 method for class 'fuzzy_logit' terms(x, ...)
x |
A fuzzy_logit object |
... |
Additional arguments |
An object of class "terms" describing the structure of
the fitted model.
Update fuzzy_logit model
## S3 method for class 'fuzzy_logit' update(object, formula., ..., evaluate = TRUE)## S3 method for class 'fuzzy_logit' update(object, formula., ..., evaluate = TRUE)
object |
A fuzzy_logit object |
formula. |
New formula (optional) |
... |
Additional arguments to pass to fuzzy_logit |
evaluate |
Logical, whether to evaluate the call |
If evaluate = TRUE, a new object of class
"fuzzy_logit" fitted with the updated formula and/or arguments.
If evaluate = FALSE, the unevaluated updated call.
Extract variable names from fuzzy_logit model
## S3 method for class 'fuzzy_logit' variable.names(object, ...)## S3 method for class 'fuzzy_logit' variable.names(object, ...)
object |
A fuzzy_logit object |
... |
Additional arguments |
A character vector of variable names, including the intercept.
Computes an approximate variance-covariance matrix using the spread parameters. Note: This is an approximation for fuzzy regression models.
## S3 method for class 'fuzzy_logit' vcov(object, ...)## S3 method for class 'fuzzy_logit' vcov(object, ...)
object |
A fuzzy_logit object |
... |
Additional arguments |
A square numeric matrix with row and column names matching the model's variable names (including the intercept).