r code

Manipulating data frame/table

To eliminate rows with condition # eliminate rows that Age is empty dat

Contingency Table for Categorical data and R

How to create contingency table from categorical data in r. Example: There are three categorical variables x1, x2, x3 measured from wild cats where x1 = gender (male, female) x2 = age (young, kitten, adult) x3 = test result ( positive = 1, negative =0). r table will generate two tables: 2by2 table for each [...]

k nearest neighbors classification (knn)

Nonparametric classification method Idea behind knn is that you measure distance between new value (x0) and each of the neighboring points and count the first k shortest distances, then classify the new value to the group that wins the majority rule. Steps: 1. Choose k as an odd integer 2. Measure the distance between xo [...]

Factor Analysis (FA)

Preparation and EDA Data should be standardized in factor analysis scale(crime.dat) #standardize data crime.dat.sd= scale(crime.dat) To obtain number of factors to use for the factor analysis, PCA can be used #PCA for EDA crime.pca<-princomp(crime.dat.sd) Bartlett scores crime.fa.s

Principle Component Analysis (PCA)

Performing a PCA after standardizing the variables and obtain estimates for the principal components for the standardized variables. Reading in athelete’s data ath.dat <- read.table(“athelete.txt”) Standardizing the data ath.dat.std <- scale(ath.dat) Correlation matrix (since covariance of standardized data is correlation) R = cov(ath.dat.std) Eigen Values lambda = eigen(R)$val Eigen values are read to assess which [...]