Hi David,

Thanks for your reply. The package is Kernlab. I agree with you when you
mention that R didn't like the structure of the testSeq object but I can't
figure out why.

Here is the output for "dput(testSeq) and str(testSeq). Any insight that you
can see would be really helpful to me.

Thanks,

Vishal

dput(testSeq)

structure(list(Class = structure(1L, .Label = "-", class = "factor"),
    V1 = structure(1L, .Label = "G", class = "factor"), V2 = structure(1L,
.Label = "G", class = "factor"),
    V3 = structure(1L, .Label = "A", class = "factor"), V4 = structure(1L,
.Label = "A", class = "factor"),
    V5 = structure(1L, .Label = "T", class = "factor"), V6 = structure(1L,
.Label = "G", class = "factor"),
    V7 = structure(1L, .Label = "G", class = "factor"), V8 = structure(1L,
.Label = "T", class = "factor"),
    V9 = structure(1L, .Label = "C", class = "factor"), V10 = structure(1L,
.Label = "G", class = "factor"),
    V11 = structure(1L, .Label = "A", class = "factor"), V12 = structure(1L,
.Label = "C", class = "factor"),
    V13 = structure(1L, .Label = "G", class = "factor"), V14 = structure(1L,
.Label = "A", class = "factor"),
    V15 = structure(1L, .Label = "A", class = "factor"), V16 = structure(1L,
.Label = "A", class = "factor"),
    V17 = structure(1L, .Label = "A", class = "factor"), V18 = structure(1L,
.Label = "T", class = "factor"),
    V19 = structure(1L, .Label = "C", class = "factor"), V20 = structure(1L,
.Label = "T", class = "factor"),
....

V497 = structure(1L, .Label = "G", class = "factor"), V498 = structure(1L,
.Label = "A", class = "factor"),
    V499 = structure(1L, .Label = "C", class = "factor"), V500 =
structure(1L, .Label = "A", class = "factor")), .Names = c("Class",
"V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9", "V10",
"V11", "V12", "V13", "V14", "V15", "V16", "V17", "V18", "V19",
"V20", "V21", "V22", "V23", "V24", "V25", "V26", "V27", "V28",
"V29", "V30", "V31", "V32", "V33", "V34", "V35", "V36", "V37",
"V38", "V39", "V40", "V41", "V42", "V43", "V44", "V45", "V46",
"V47", "V48", "V49", "V50", "V51", "V52", "V53", "V54", "V55",
"V56", "V57", "V58", "V59", "V60", "V61", "V62", "V63", "V64",
"V65", "V66", "V67", "V68", "V69", "V70", "V71", "V72", "V73",
"V74", "V75", "V76", "V77", "V78", "V79", "V80", "V81", "V82",
"V83", "V84", "V85", "V86", "V87", "V88", "V89", "V90", "V91",
"V92", "V93", "V94", "V95", "V96", "V97", "V98", "V99", "V100",
"V101", "V102", "V103", "V104", "V105", "V106", "V107", "V108",
"V109", "V110", "V111", "V112", "V113", "V114", "V115", "V116",
"V117", "V118", "V119", "V120", "V121", "V122", "V123", "V124",
"V125", "V126", "V127", "V128", "V129", "V130", "V131", "V132",
"V133", "V134", "V135", "V136", "V137", "V138", "V139", "V140",
"V141", "V142", "V143", "V144", "V145", "V146", "V147", "V148",
"V149", "V150", "V151", "V152", "V153", "V154", "V155", "V156",
"V157", "V158", "V159", "V160", "V161", "V162", "V163", "V164",
"V165", "V166", "V167", "V168", "V169", "V170", "V171", "V172",
"V173", "V174", "V175", "V176", "V177", "V178", "V179", "V180",
"V181", "V182", "V183", "V184", "V185", "V186", "V187", "V188",
"V189", "V190", "V191", "V192", "V193", "V194", "V195", "V196",
"V197", "V198", "V199", "V200", "V201", "V202", "V203", "V204",
"V205", "V206", "V207", "V208", "V209", "V210", "V211", "V212",
"V213", "V214", "V215", "V216", "V217", "V218", "V219", "V220",
"V221", "V222", "V223", "V224", "V225", "V226", "V227", "V228",
"V229", "V230", "V231", "V232", "V233", "V234", "V235", "V236",
"V237", "V238", "V239", "V240", "V241", "V242", "V243", "V244",
"V245", "V246", "V247", "V248", "V249", "V250", "V251", "V252",
"V253", "V254", "V255", "V256", "V257", "V258", "V259", "V260",
"V261", "V262", "V263", "V264", "V265", "V266", "V267", "V268",
"V269", "V270", "V271", "V272", "V273", "V274", "V275", "V276",
"V277", "V278", "V279", "V280", "V281", "V282", "V283", "V284",
"V285", "V286", "V287", "V288", "V289", "V290", "V291", "V292",
"V293", "V294", "V295", "V296", "V297", "V298", "V299", "V300",
"V301", "V302", "V303", "V304", "V305", "V306", "V307", "V308",
"V309", "V310", "V311", "V312", "V313", "V314", "V315", "V316",
"V317", "V318", "V319", "V320", "V321", "V322", "V323", "V324",
"V325", "V326", "V327", "V328", "V329", "V330", "V331", "V332",
"V333", "V334", "V335", "V336", "V337", "V338", "V339", "V340",
"V341", "V342", "V343", "V344", "V345", "V346", "V347", "V348",
"V349", "V350", "V351", "V352", "V353", "V354", "V355", "V356",
"V357", "V358", "V359", "V360", "V361", "V362", "V363", "V364",
"V365", "V366", "V367", "V368", "V369", "V370", "V371", "V372",
"V373", "V374", "V375", "V376", "V377", "V378", "V379", "V380",
"V381", "V382", "V383", "V384", "V385", "V386", "V387", "V388",
"V389", "V390", "V391", "V392", "V393", "V394", "V395", "V396",
"V397", "V398", "V399", "V400", "V401", "V402", "V403", "V404",
"V405", "V406", "V407", "V408", "V409", "V410", "V411", "V412",
"V413", "V414", "V415", "V416", "V417", "V418", "V419", "V420",
"V421", "V422", "V423", "V424", "V425", "V426", "V427", "V428",
"V429", "V430", "V431", "V432", "V433", "V434", "V435", "V436",
"V437", "V438", "V439", "V440", "V441", "V442", "V443", "V444",
"V445", "V446", "V447", "V448", "V449", "V450", "V451", "V452",
"V453", "V454", "V455", "V456", "V457", "V458", "V459", "V460",
"V461", "V462", "V463", "V464", "V465", "V466", "V467", "V468",
"V469", "V470", "V471", "V472", "V473", "V474", "V475", "V476",
"V477", "V478", "V479", "V480", "V481", "V482", "V483", "V484",
"V485", "V486", "V487", "V488", "V489", "V490", "V491", "V492",
"V493", "V494", "V495", "V496", "V497", "V498", "V499", "V500"
), row.names = c(NA, -1L), class = "data.frame")
---------------------------------------------------------------------------------------------
str(testSeq)

'data.frame':   1 obs. of  501 variables:
 $ Class: Factor w/ 1 level "-": 1
 $ V1   : Factor w/ 1 level "G": 1
 $ V2   : Factor w/ 1 level "G": 1
 $ V3   : Factor w/ 1 level "A": 1
 $ V4   : Factor w/ 1 level "A": 1
 $ V5   : Factor w/ 1 level "T": 1
 $ V6   : Factor w/ 1 level "G": 1
 $ V7   : Factor w/ 1 level "G": 1
 $ V8   : Factor w/ 1 level "T": 1
 $ V9   : Factor w/ 1 level "C": 1
 $ V10  : Factor w/ 1 level "G": 1
 $ V11  : Factor w/ 1 level "A": 1
 $ V12  : Factor w/ 1 level "C": 1
 $ V13  : Factor w/ 1 level "G": 1
 $ V14  : Factor w/ 1 level "A": 1
 $ V15  : Factor w/ 1 level "A": 1
 $ V16  : Factor w/ 1 level "A": 1
 $ V17  : Factor w/ 1 level "A": 1
 $ V18  : Factor w/ 1 level "T": 1
 $ V19  : Factor w/ 1 level "C": 1
 $ V20  : Factor w/ 1 level "T": 1
......
$ V493 : Factor w/ 1 level "T": 1
 $ V494 : Factor w/ 1 level "G": 1
 $ V495 : Factor w/ 1 level "T": 1
 $ V496 : Factor w/ 1 level "G": 1
 $ V497 : Factor w/ 1 level "G": 1
 $ V498 : Factor w/ 1 level "A": 1
 $ V499 : Factor w/ 1 level "C": 1
 $ V500 : Factor w/ 1 level "A": 1


On Fri, Dec 25, 2009 at 12:15 AM, David Winsemius <dwinsemius@comcast.net>wrote:

>
> On Dec 24, 2009, at 11:42 PM, Vishal Thapar wrote:
>
>  Hi useR's,
>>
>> I am resending this request since I got no response for my last post and I
>> am new to the list so pardon me if I am violating the protocol.
>>
>> I am trying to use the "Kernlab" package for training and prediction using
>> SVM's. I am getting the following error when I am trying to use the
>> predict
>> function:
>>
>
> I'm guessing that the package is really "kernlab".
>
>
>
>>  predictSvm = predict(modelforSVM, testSeq);
>>>
>> Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") :   contrasts
>> can
>> be applied only to factors with 2 or more levels
>>
>
> Sounds like R does not like the structure of your testSeq argument. Perhaps
> it was expecting a factor argument with levels that matched those used in
> the training set?
>
>
>
>> The training file is a data frame with 501 columns: Col 1 is "Class" which
>> is "+" or "-" and Cols V1 to V500 are "A/C/G/T" . There are 200 seq's for
>> training (100 + and - each). this is very similar to the "promotergene"
>> data
>> set included as example with the package.
>>
>
>
>> The model that I have generated is as follows:
>>
>> modelforSVM <- ksvm(Class ~ ., data = train500, kernel = "rbfdot", kpar =
>> "automatic", C = 60, cross = 3, prob.model = TRUE)
>>
>> The testSeq is a vector of 500 characters casted as a data.frame. I tried
>> adding the Class column as well later to the testSeq data frame but got
>> the
>> same error.
>>
>>
> Why not offer the results of dput() on that object. Or you could offer the
> output of str(testSeq) , even if you aren't going to create a smaller test
> object that could be used for testing.
>
>
>  I am using R with windows, 32 bit, version 2.9.0
>>
>> Any help that I can get is really appreciated.
>>
>> Thanks,
>>
>> Vishal
>>
>
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
>


-- 
Vishal Thapar, Ph.D.
Post Doctoral Researcher
Cold Spring Harbor Lab
Williams Bldg

1 Bungtown Road
Cold Spring Harbor, NY - 11724

	[[alternative HTML version deleted]]


