Learn R Programming

condvis (version 0.2-2)

visualweight: Assign weights to observations according to proximity in predictor space

Description

This function assigns a weight (between 0 and 1) to observations in a data set according to their proximity to a given point in the space.

Usage

visualweight(xc.cond, xc, sigma = NULL, distance = "euclidean", basicoutput = FALSE)

Arguments

xc.cond
a dataframe containing numeric values or factors.
xc
a dataframe containing numeric values or factors.
sigma
a numeric value greater than zero, defaults to 1. Used to scale the distance function for assigning weights. Larger values show more data, smaller values show less data.
distance
distance metric used, "euclidean" (default), "maxnorm" or "daisy". See dist1 and daisy1.
basicoutput
if TRUE, just returns the visual weights. If FALSE, returns a list containing non-zero weight values, and an order vector

Value

  • A list:
  • kweights between 0 and 1
  • orderorder index of k from smallest to largest, excluding zero values.

Details

Observations where the categorical predictor levels do not match are assigned weights 0 first. Then observations are assigned weights between 0 and 1 according to a distance measure (dist1).

Examples

Run this code
## Highlighting cases near the first observation

vw <- visualweight(mtcars[1, ], mtcars, sigma = 2)
print(vw)

## Its use in an interactive ceplot
library(mgcv)
library(e1071)

data(powerplant)
model <- list(gam = gam(PE ~ s(AT) + s(V) + s(AP) + s(RH), data = powerplant), 
              svm = svm(PE ~ ., data = powerplant))

interactiveceplot(data = powerplant, model = model, S = "V",
    height = 6, width = 10, sigma = 0.2)

Run the code above in your browser using DataLab