uwIntroStats (version 0.0.7)

U: Create a Transformed Variable

Description

Creates a transformed variable using either the natural log, a dummy transformation, linear splines, or a polynomial. Mostly for use in regression. If a partial formula of the form ~var1 + var2 is entered, returns the formula for use in regression. The partial formula can be named by adding an equals sign before the tilde.

Usage

U(..., type=NULL, subset=rep(T,length(x)), knots=NULL, degree=2, 
  reference=sort(unique(x[!is.na(x)])), lbl=NULL, center=mean(x,na.rm=T), 
  includeAll=FALSE, parameterization="absolute", vrsn=FALSE)

Arguments

...

variable(s) used to create the transformation.

type

a character string describing the transformation. Partial matching is used, so only enough of the string to make the transformation unique is needed.

subset

used in creating dummy variables. Only used if type == "dummy".

knots

vector of knots to create the splines. Only used if type=="lspline".

degree

the degree of the polynomial to be returned. Only used if type=="polynomial".

reference

the reference vector for levels of the dummy variable. Only used if type=="dummy".

lbl

a label for the splines. Only used if type=="lspline"

center

the center of the returned polynomial. Only used if type=="polynomial".

includeAll

a logical value to use all values even in the presense of a subset. Only used if type=="dummy".

parameterization

defaults to"absolute", and provides splines based on the absolute slope between knots. If "change", provides splines based on the change from knot to knot. If lsplineD is called, "change" is entered by default. Only used if type=="lspline".

vrsn

if TRUE, returns the version of the function and nothing else.

Value

A matrix or vector containing the transformations. The class of the returned value is c("transformation", y) where y is the class of the transformed variable (usually numeric). The type of transformation performed is encoded as one of the attributes of the returned value, along with the original data.

See Also

regress

Examples

Run this code
# NOT RUN {
# Reading in a dataset
mri <- read.table("http://www.emersonstatistics.com/datasets/mri.txt", header=TRUE)
attach(mri)
# Create a spline based on absolute
U(ldl, type="lspline", knots=c(70, 100, 130, 160))
U(ldl, type="ls", knots=c(70,100,130,160))

# Create a spline based on change
U(ldl, type="ls", knots=c(70, 100, 130, 160), parameterization="change")

# Create a log transformed variable
U(age, type="log")

## Create a partial formula
U(ma=~male+age)

# }

Run the code above in your browser using DataLab