Hi,
Until recently I was using the knncat classifier function of
knncat on an old computer (2.12, Mac OS X 10.4), and
everything worked great.
However, now that I have updated to R 2.14.1 (on Mac OS X
10.7), knncat seems broken. Problems:
1. It seems to output verbose output by default, and
regardless of whether I put 0 or 1 into the verbose option.
2. It seems to just predict everything to be class "0".
3. I can see this problem even when running the example
script under ?knncat.
Given example from ?knncat, and expected behavior:
======================library(knncat)
library(MASS) # Load data set
syncat <- knncat (synth.tr, classcol=3)
## Not run: syncat
Train set misclass rate: 12.8
synpred <- predict (syncat, synth.tr, synth.te,
train.classcol=3,
newdata.classcol=3)
table (synpred, synth.te$yc)
synpred 0 1
0 460 91
1 40 409
======================
Actual behavior:
========================================= > library(MASS) # Load data set
> syncat <- knncat (synth.tr, classcol=3)
Global U:
[,1] [,2] [,3] [,4]
[,5]
[1,] 3.20705e+02 1.91438e+02 1.51645e+02 1.20514e+02
8.21981e+01
[2,] 1.91438e+02 1.14799e+02 9.09814e+01 7.22355e+01
4.92108e+01
[3,] 1.51645e+02 9.09814e+01 7.21094e+01 5.72461e+01
3.89942e+01
[4,] 1.20514e+02 7.22355e+01 5.72461e+01 4.54553e+01
3.09702e+01
[5,] 8.21981e+01 4.92108e+01 3.89942e+01 3.09702e+01
2.11076e+01
[6,] 5.57264e+01 3.34476e+01 2.65108e+01 2.10446e+01
1.43334e+01
[7,] 2.51586e+01 1.52490e+01 1.20991e+01 9.58523e+00
6.51199e+00
[8,] 1.45272e+01 8.85590e+00 7.03089e+00 5.56357e+00
3.77419e+00
[9,] 8.30201e+00 5.07964e+00 4.03440e+00 3.19007e+00
2.16202e+00
[10,] 3.36454e+00 2.07002e+00 1.64502e+00 1.29931e+00
8.79344e-01
[,6] [,7] [,8] [,9]
[,10]
[1,] 5.57264e+01 2.51586e+01 1.45272e+01 8.30201e+00
3.36454e+00
[2,] 3.34476e+01 1.52490e+01 8.85590e+00 5.07964e+00
2.07002e+00
[3,] 2.65108e+01 1.20991e+01 7.03089e+00 4.03440e+00
1.64502e+00
[4,] 2.10446e+01 9.58523e+00 5.56357e+00 3.19007e+00
1.29931e+00
[5,] 1.43334e+01 6.51199e+00 3.77419e+00 2.16202e+00
8.79344e-01
[6,] 9.74699e+00 4.45226e+00 2.58857e+00 1.48583e+00
6.06140e-01
[7,] 4.45226e+00 2.07551e+00 1.22083e+00 7.05915e-01
2.91111e-01
[8,] 2.58857e+00 1.22083e+00 7.22786e-01 4.19620e-01
1.74066e-01
[9,] 1.48583e+00 7.05915e-01 4.19620e-01 2.44220e-01
1.01671e-01
[10,] 6.06140e-01 2.91111e-01 1.74066e-01 1.01671e-01
4.25445e-02
Global W:
[,1] [,2] [,3] [,4]
[,5]
[1,] 3.68224e+02 2.36787e+02 1.93972e+02 1.58837e+02
1.12597e+02
[2,] 2.36787e+02 1.58549e+02 1.32054e+02 1.09539e+02
7.88945e+01
[3,] 1.93972e+02 1.32054e+02 1.11021e+02 9.27903e+01
6.74442e+01
[4,] 1.58837e+02 1.09539e+02 9.27903e+01 7.82101e+01
5.74745e+01
[5,] 1.12597e+02 7.88945e+01 6.74442e+01 5.74745e+01
4.31835e+01
[...etc...lots of undesired detailed/verbose output, then...]
> syncat
Training set misclass rate: 50%
> synpred <- predict (syncat, synth.tr, synth.te,
train.classcol=3,
+ newdata.classcol=3)
> table (synpred, synth.te$yc)
synpred 0 1
0 500 500
=========================================
Any help would be much appreciated!
Cheers,
Nick
PS computer details
====================knncat is version 1.1.11
====================
=========================================R version 2.14.1 (2011-12-22)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
[R.app GUI 1.43 (5989) x86_64-apple-darwin9.8.0]
=========================================
--
===================================================Nicholas J. Matzke
Ph.D. Candidate, Graduate Student Researcher
Huelsenbeck Lab
Center for Theoretical Evolutionary Genomics
4151 VLSB (Valley Life Sciences Building)
Department of Integrative Biology
University of California, Berkeley
Graduate Student Instructor, IB200B
Principles of Phylogenetics: Ecology and Evolution
http://ib.berkeley.edu/courses/ib200b/
http://phylo.wikidot.com/
Lab websites:
http://ib.berkeley.edu/people/lab_detail.php?lab=54
http://fisher.berkeley.edu/cteg/hlab.html
Dept. personal page:
http://ib.berkeley.edu/people/students/person_detail.php?person=370
Lab personal page:
http://fisher.berkeley.edu/cteg/members/matzke.html
Lab phone: 510-643-6299
Dept. fax: 510-643-6264
Cell phone: 510-301-0179
Email: matzke at berkeley.edu
Mailing address:
Department of Integrative Biology
1005 Valley Life Sciences Building #3140
Berkeley, CA 94720-3140
-----------------------------------------------------
"[W]hen people thought the earth was flat, they were wrong.
When people thought the earth was spherical, they were
wrong. But if you think that thinking the earth is spherical
is just as wrong as thinking the earth is flat, then your
view is wronger than both of them put together."
Isaac Asimov (1989). "The Relativity of Wrong." The
Skeptical Inquirer, 14(1), 35-44. Fall 1989.
http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm