
On Dec 25, 2009, at 1:18 AM, Vishal Thapar wrote:

> Hi David,
>
> Thanks for your reply. The package is Kernlab.

No, the package name is "kernlab". Case of characters matters in R, as  
the rest of your problems also illustrate as well.

> 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)
>

These factors only have one level each. They need four levels.


> 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"),
snipped

>
> 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",

> snipped
> "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

You probably out to read your data in with stringsAsFactors=FALSE and  
work with the characters before converting the columns in the  
dataframe to factors. At the moment, I am guessing htat you read them  
in a single line at a time and then bound them together somehow.
>
>
> 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

David Winsemius, MD
Heritage Laboratories
West Hartford, CT


	[[alternative HTML version deleted]]


