Home > Software engineering >  How to model this dataset using logistic regression
How to model this dataset using logistic regression

Time:09-18

Assume we have the following dataset :

    data_01=structure(list(pcb_type = c("01", "01", "01", "01", "01", "01", 
"01", "01", "01", "01", "01", "01", "01", "01", "01", "01", "01", 
"01", "01", "01", "01", "01", "01", "01", "01", "01", "01", "01", 
"01", "01", "01", "01", "01", "01", "01", "01", "01", "01", "01", 
"01", "01", "01", "01", "01", "01", "01", "01", "01", "01", "01"
), Defect_type = c("Spur", "Spurious_copper", "Open_circuit", 
"Missinghole", "Missinghole", "Open_circuit", "Mouse_bite", "Mouse_bite", 
"Mouse_bite", "Short", "Spur", "Spur", "Open_circuit", "Spurious_copper", 
"Short", "Spur", "Spur", "Open_circuit", "Mouse_bite", "Missinghole", 
"Spurious_copper", "Spur", "Spur", "Short", "Missinghole", "Spur", 
"Spurious_copper", "Short", "Missinghole", "Missinghole", "Mouse_bite", 
"Spurious_copper", "Short", "Missinghole", "Mouse_bite", "Spurious_copper", 
"Missinghole", "Spurious_copper", "Open_circuit", "Spur", "Open_circuit", 
"Spur", "Short", "Spurious_copper", "Short", "Open_circuit", 
"Open_circuit", "Spur", "Spurious_copper", "Mouse_bite"), sd1 = c(0.168093044472351, 
0.168089374451317, 0.168108562502649, 0.167815195697288, 0.167847724873945, 
0.16810873476238, 0.168094615391722, 0.168094832629513, 0.168090824029403, 
0.168104705200358, 0.168091792928968, 0.168093383189173, 0.168108547560401, 
0.168090039624253, 0.168102633129542, 0.168093164238512, 0.168092960361196, 
0.168106872394283, 0.16809478473714, 0.167722186968605, 0.16804216428349, 
0.168093088373005, 0.168093038482056, 0.168102015142555, 0.167809284810308, 
0.168093110854311, 0.168087651208363, 0.168105849190783, 0.167746769335133, 
0.167849511559066, 0.168094784953946, 0.168088610795341, 0.168104926560611, 
0.167850574237067, 0.168094189412324, 0.168088949614829, 0.167890852295518, 
0.168088539848386, 0.168108496900373, 0.168093288099756, 0.168108120045769, 
0.168092047028413, 0.16810408379863, 0.168091109609073, 0.168101530362186, 
0.168108505278839, 0.168106416419314, 0.168093871326839, 0.168091040500625, 
0.168094408586592), sum1 = c(393059.572549021, 393079.313725492, 
393027.627450982, 392146.639215688, 392215.682352943, 393017.572549021, 
393006.898039217, 393000.043137256, 392982.827450982, 393073.345098041, 
393060.266666668, 393025.564705884, 393020.949019609, 393070.227450982, 
393133.180392158, 393058.035294119, 393039.964705884, 393006.49019608, 
393005.0627451, 391646.129411766, 392904.658823531, 393032.058823531, 
393057.133333335, 393139.705882354, 392068.513725492, 393038.564705884, 
393099.239215688, 393058.721568629, 391861.97647059, 392252.168627452, 
393004.51764706, 393089.494117649, 393089.870588237, 392207.17647059, 
393016.537254903, 393084.886274511, 392317.811764707, 393088.800000002, 
393025.243137256, 393072.11764706, 393029.043137256, 393038.305882354, 
393098.137254903, 393057.639215688, 393139.125490198, 393026.682352943, 
393010.200000001, 393070.749019609, 393057.552941178, 393008.627450982
), sd2 = c(0.102918564423537, 0.102903819301957, 0.102934951772047, 
0.102839152618511, 0.102852427907075, 0.10292775591514, 0.102926166981337, 
0.102928469086841, 0.10292859583443, 0.10291628816225, 0.102917283917233, 
0.102920633644626, 0.102938811841729, 0.10291081550011, 0.102919071918386, 
0.102918408473999, 0.102920511522864, 0.102939412767276, 0.102928195461307, 
0.102841063501655, 0.10290180394199, 0.102919556699571, 0.102917590776993, 
0.10291517600863, 0.102849213165337, 0.10292136491308, 0.102908365433255, 
0.102922469496974, 0.102829734862424, 0.102855965707123, 0.102925942938647, 
0.102896158734185, 0.102924112959045, 0.102853690122406, 0.102925489451006, 
0.102897214435311, 0.102876934917686, 0.102898784071186, 0.102939203427981, 
0.102915095129317, 0.102924837437659, 0.102917724015655, 0.102918407920674, 
0.102903881555672, 0.102908683817266, 0.102929317065015, 0.102937441045949, 
0.102917212166919, 0.102901626389135, 0.102929288970722), sum2 = c(1577299.52156865, 
1577516.49803924, 1577210.89411767, 1576871.70980394, 1576918.8901961, 
1577221.2784314, 1577211.2901961, 1577218.07058826, 1577203.71764708, 
1577381.65490198, 1577300.9529412, 1577275.54901963, 1577191.57647061, 
1577448.7529412, 1577438.62352943, 1577298.11372551, 1577299.18039218, 
1577192.53333336, 1577203.54117649, 1576670.14901963, 1577343.43137257, 
1577288.17254904, 1577295.79215689, 1577487.55686277, 1576806.36470591, 
1577278.38431375, 1577540.09803924, 1577351.15686277, 1576692.54901963, 
1576925.41176473, 1577215.47450983, 1577563.83137257, 1577362.627451, 
1576893.9529412, 1577244.65882355, 1577559.01176473, 1576933.92549022, 
1577568.32941179, 1577196.73725493, 1577312.17647061, 1577251.17254904, 
1577278.1529412, 1577406.52941179, 1577444.74117649, 1577517.54117649, 
1577242.06274512, 1577197.2901961, 1577311.23921571, 1577487.87058826, 
1577191.50980394), sd3 = c(0.14193777930703, 0.141933062715293, 
0.141954797466963, 0.141722830875481, 0.141756685839469, 0.141955914403182, 
0.141940674063666, 0.14194194746325, 0.141937515209358, 0.141949128588433, 
0.141935776889511, 0.14193848184079, 0.141957171250499, 0.141928723435643, 
0.141946037885005, 0.141938160642707, 0.141938139845344, 0.14195378655123, 
0.141941822316246, 0.14168303351368, 0.141901687788322, 0.141937970123023, 
0.141935951195291, 0.141946929492314, 0.141738609155861, 0.141937986047919, 
0.14192468324531, 0.141950152244626, 0.141680783944809, 0.141749832435663, 
0.141941868895542, 0.141930616929521, 0.141950268578409, 0.14176935089913, 
0.14194016916176, 0.141932504485756, 0.14180029894561, 0.141927246794768, 
0.141957057393608, 0.141937831648352, 0.141958395983641, 0.141937699685645, 
0.141948664786789, 0.141934216456196, 0.141945515907224, 0.141957723322229, 
0.141954912367759, 0.141938606841573, 0.141934847133214, 0.141941942200025
), sum3 = c(516702.294117652, 516745.466666672, 516673.423529417, 
515894.184313731, 515963.741176476, 516647.960784319, 516645.372549025, 
516632.894117652, 516645.266666672, 516769.749019613, 516703.552941181, 
516667.623529417, 516648.027450985, 516773.066666672, 516801.392156868, 
516700.827450985, 516678.933333338, 516657.44313726, 516635.239215691, 
515495.478431378, 516617.341176476, 516677.27058824, 516711.203921574, 
516793.117647064, 515860.772549025, 516681.317647064, 516820.505882358, 
516726.901960789, 515665.035294123, 515992.305882358, 516635.874509809, 
516768.87058824, 516743.874509809, 515977.650980397, 516656.75686275, 
516752.309803927, 516076.537254907, 516798.031372554, 516649.282352946, 
516714.854901966, 516641.498039221, 516681.027450985, 516756.658823534, 
516724.560784319, 516819.12941177, 516644.882352946, 516647.294117652, 
516713.678431378, 516722.878431378, 516636.121568632), ` Min. 1` = c(0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0), `1st Qu. 1` = c(0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
), `Median 1` = c(0.00784313725490196, 0.00784313725490196, 0.00784313725490196, 
0.00784313725490196, 0.00784313725490196, 0.00784313725490196, 
0.00784313725490196, 0.00784313725490196, 0.00784313725490196, 
0.00784313725490196, 0.00784313725490196, 0.00784313725490196, 
0.00784313725490196, 0.00784313725490196, 0.00784313725490196, 
0.00784313725490196, 0.00784313725490196, 0.00784313725490196, 
0.00784313725490196, 0.00784313725490196, 0.00784313725490196, 
0.00784313725490196, 0.00784313725490196, 0.00784313725490196, 
0.00784313725490196, 0.00784313725490196, 0.00784313725490196, 
0.00784313725490196, 0.00784313725490196, 0.00784313725490196, 
0.00784313725490196, 0.00784313725490196, 0.00784313725490196, 
0.00784313725490196, 0.00784313725490196, 0.00784313725490196, 
0.00784313725490196, 0.00784313725490196, 0.00784313725490196, 
0.00784313725490196, 0.00784313725490196, 0.00784313725490196, 
0.00784313725490196, 0.00784313725490196, 0.00784313725490196, 
0.00784313725490196, 0.00784313725490196, 0.00784313725490196, 
0.00784313725490196, 0.00784313725490196), `Mean 1` = c(0.0816844930528869, 
0.0816885956065579, 0.081677854315858, 0.0814947699123439, 0.0815091182555964, 
0.0816757647354818, 0.0816735463900129, 0.0816721218242964, 0.0816685441106261, 
0.0816873552238231, 0.0816846373023902, 0.0816774256421929, 0.0816764664237442, 
0.0816867073235114, 0.0816997900199914, 0.0816841735850605, 0.0816804182081601, 
0.0816734616332424, 0.0816731649845462, 0.0813907554258473, 0.081652299334638, 
0.081678775230766, 0.0816839861422029, 0.0817011461283164, 0.0814785341010145, 
0.0816801272642465, 0.0816927364637692, 0.0816843162046256, 0.0814356121315691, 
0.0815167007266637, 0.0816730517038631, 0.0816907112659399, 0.0816907895029587, 
0.0815073505879538, 0.0816755495836805, 0.0816897536774292, 0.0815303424918403, 
0.0816905670164365, 0.0816773588147392, 0.0816871001385431, 0.0816781485196472, 
0.0816800734762963, 0.0816925074574957, 0.0816840912731969, 0.0817010255129125, 
0.0816776579083423, 0.0816742325938647, 0.0816868157143812, 0.0816840733438802, 
0.0816739057913177), `3rd Qu. 1` = c(0.0431372549019608, 0.0431372549019608, 
0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 
0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 
0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 
0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 
0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 
0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 
0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 
0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 
0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 
0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 
0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 
0.0431372549019608, 0.0431372549019608, 0.0431372549019608, 0.0431372549019608
), `Max. 1` = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ` Min. 2` = c(0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0), `1st Qu. 2` = c(0.270588235294118, 0.270588235294118, 
0.270588235294118, 0.270588235294118, 0.270588235294118, 0.270588235294118, 
0.270588235294118, 0.270588235294118, 0.270588235294118, 0.270588235294118, 
0.270588235294118, 0.270588235294118, 0.270588235294118, 0.270588235294118, 
0.270588235294118, 0.270588235294118, 0.270588235294118, 0.270588235294118, 
0.270588235294118, 0.270588235294118, 0.270588235294118, 0.270588235294118, 
0.270588235294118, 0.270588235294118, 0.270588235294118, 0.270588235294118, 
0.270588235294118, 0.270588235294118, 0.270588235294118, 0.270588235294118, 
0.270588235294118, 0.270588235294118, 0.270588235294118, 0.270588235294118, 
0.270588235294118, 0.270588235294118, 0.270588235294118, 0.270588235294118, 
0.270588235294118, 0.270588235294118, 0.270588235294118, 0.270588235294118, 
0.270588235294118, 0.270588235294118, 0.270588235294118, 0.270588235294118, 
0.270588235294118, 0.270588235294118, 0.270588235294118, 0.270588235294118
), `Median 2` = c(0.341176470588235, 0.341176470588235, 0.341176470588235, 
0.341176470588235, 0.341176470588235, 0.341176470588235, 0.341176470588235, 
0.341176470588235, 0.341176470588235, 0.341176470588235, 0.341176470588235, 
0.341176470588235, 0.341176470588235, 0.341176470588235, 0.341176470588235, 
0.341176470588235, 0.341176470588235, 0.341176470588235, 0.341176470588235, 
0.341176470588235, 0.341176470588235, 0.341176470588235, 0.341176470588235, 
0.341176470588235, 0.341176470588235, 0.341176470588235, 0.341176470588235, 
0.341176470588235, 0.341176470588235, 0.341176470588235, 0.341176470588235, 
0.341176470588235, 0.341176470588235, 0.341176470588235, 0.341176470588235, 
0.341176470588235, 0.341176470588235, 0.341176470588235, 0.341176470588235, 
0.341176470588235, 0.341176470588235, 0.341176470588235, 0.341176470588235, 
0.341176470588235, 0.341176470588235, 0.341176470588235, 0.341176470588235, 
0.341176470588235, 0.341176470588235, 0.341176470588235), `Mean 2` = c(0.327789782541999, 
0.327834873958777, 0.327771364243834, 0.327700875949812, 0.327710680841193, 
0.327773522281601, 0.327771446555698, 0.327772855637004, 0.327769872850664, 
0.327806851251591, 0.327790080005664, 0.327784800636836, 0.327767349706809, 
0.327820795370246, 0.32781869030546, 0.327789489968148, 0.327789711639701, 
0.327767548559232, 0.327769836177061, 0.327658988175958, 0.327798907749281, 
0.327787424021871, 0.327789007506532, 0.327828859487961, 0.327687296122275, 
0.327785389859384, 0.327839778441891, 0.327800513238103, 0.327663643278574, 
0.327712036134549, 0.327772316127562, 0.327844710633948, 0.327802897022268, 
0.32770549845367, 0.327778381126454, 0.327843709037114, 0.32771380543213, 
0.327845645403328, 0.327768422205941, 0.327792412446786, 0.327779734789872, 
0.327785341776216, 0.327812020599612, 0.327819961657015, 0.327835090740517, 
0.327777841617012, 0.327768537116563, 0.327792217669208, 0.327828924685476, 
0.327767335852337), `3rd Qu. 2` = c(0.36078431372549, 0.36078431372549, 
0.36078431372549, 0.36078431372549, 0.36078431372549, 0.36078431372549, 
0.36078431372549, 0.36078431372549, 0.36078431372549, 0.36078431372549, 
0.36078431372549, 0.36078431372549, 0.36078431372549, 0.36078431372549, 
0.36078431372549, 0.36078431372549, 0.36078431372549, 0.36078431372549, 
0.36078431372549, 0.36078431372549, 0.36078431372549, 0.36078431372549, 
0.36078431372549, 0.36078431372549, 0.36078431372549, 0.36078431372549, 
0.36078431372549, 0.36078431372549, 0.36078431372549, 0.36078431372549, 
0.36078431372549, 0.36078431372549, 0.36078431372549, 0.36078431372549, 
0.36078431372549, 0.36078431372549, 0.36078431372549, 0.36078431372549, 
0.36078431372549, 0.36078431372549, 0.36078431372549, 0.36078431372549, 
0.36078431372549, 0.36078431372549, 0.36078431372549, 0.36078431372549, 
0.36078431372549, 0.36078431372549, 0.36078431372549, 0.36078431372549
), `Max. 2` = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ` Min. 3` = c(0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0), `1st Qu. 3` = c(0.0392156862745098, 0.0392156862745098, 
0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 
0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 
0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 
0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 
0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 
0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 
0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 
0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 
0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 
0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 
0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 
0.0392156862745098, 0.0392156862745098, 0.0392156862745098, 0.0392156862745098
), `Median 3` = c(0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 
0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 
0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 
0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 
0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 
0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 
0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 
0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 
0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 
0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 
0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 
0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 
0.0588235294117647, 0.0588235294117647, 0.0588235294117647), 
    `Mean 3` = c(0.107379562544555, 0.107388534537675, 0.107373562743179, 
    0.107211623523922, 0.107226078628106, 0.107368271149817, 
    0.107367733270314, 0.107365140039129, 0.107367711266152, 
    0.107393580825384, 0.107379824149587, 0.10737235740411, 0.10736828500429, 
    0.107394270289112, 0.107400156809804, 0.10737925774617, 0.107374707774548, 
    0.107370241744727, 0.107365627390559, 0.107128765631247, 
    0.107361907872292, 0.107374362227715, 0.107381414153999, 
    0.10739843722533, 0.107204679988508, 0.107375203275667, 0.107404128968444, 
    0.107384676474688, 0.107164002443538, 0.107232014861904, 
    0.107365759415527, 0.107393398272341, 0.107388203660283, 
    0.107228969322956, 0.107370099125162, 0.107389956658485, 
    0.107249519579881, 0.107399458381419, 0.107368545794352, 
    0.107382172890088, 0.107366928080996, 0.107375142967965, 
    0.107390860459045, 0.107384189938227, 0.107403842914344, 
    0.107367631399195, 0.107368132605097, 0.107381928399404, 
    0.107383840316549, 0.107365810758571), `3rd Qu. 3` = c(0.0901960784313725, 
    0.0901960784313725, 0.0901960784313725, 0.0901960784313725, 
    0.0901960784313725, 0.0901960784313725, 0.0901960784313725, 
    0.0901960784313725, 0.0901960784313725, 0.0901960784313725, 
    0.0901960784313725, 0.0901960784313725, 0.0901960784313725, 
    0.0901960784313725, 0.0901960784313725, 0.0901960784313725, 
    0.0901960784313725, 0.0901960784313725, 0.0901960784313725, 
    0.0901960784313725, 0.0901960784313725, 0.0901960784313725, 
    0.0901960784313725, 0.0901960784313725, 0.0901960784313725, 
    0.0901960784313725, 0.0901960784313725, 0.0901960784313725, 
    0.0901960784313725, 0.0901960784313725, 0.0901960784313725, 
    0.0901960784313725, 0.0901960784313725, 0.0901960784313725, 
    0.0901960784313725, 0.0901960784313725, 0.0901960784313725, 
    0.0901960784313725, 0.0901960784313725, 0.0901960784313725, 
    0.0901960784313725, 0.0901960784313725, 0.0901960784313725, 
    0.0901960784313725, 0.0901960784313725, 0.0901960784313725, 
    0.0901960784313725, 0.0901960784313725, 0.0901960784313725, 
    0.0901960784313725), `Max. 3` = c(1, 1, 1, 1, 1, 1, 1, 1, 
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
    1, 1, 1, 1)), row.names = c(96L, 112L, 50L, 19L, 4L, 51L, 
35L, 34L, 29L, 77L, 100L, 84L, 54L, 102L, 67L, 89L, 85L, 53L, 
40L, 5L, 101L, 83L, 94L, 71L, 17L, 93L, 120L, 61L, 11L, 14L, 
33L, 113L, 64L, 10L, 38L, 111L, 12L, 114L, 59L, 90L, 43L, 92L, 
72L, 116L, 76L, 47L, 56L, 91L, 115L, 27L), class = "data.frame")

I'm searching to build a multinomial logistic model that predict the defect type / second column.

I tried :

library(nnet)
formula <- "Defect_type ~."
mod <- multinom(formula, data=data_01)
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1   isOF[nn]]) : 
  contrasts can be applied only to factors with 2 or more levels 

Thank you for help.

CodePudding user response:

If we remove the first column, which have only a single unique value, it should work

library(nnet)
formula <- Defect_type ~.
multinom(formula, data=data_01[-1])

The non-numeric columns were character class, so changed it to factor and checked the levels

> i1 <- sapply(data_01, is.character)
> data_01[i1] <- lapply(data_01[i1], factor)
> sapply(data_01[i1], nlevels)
   pcb_type Defect_type 
          1           6 

Thus, we remove the column with the single levels

  •  Tags:  
  • r
  • Related