[R] (no subject)

Daniel Malter daniel at umd.edu
Tue Jun 21 09:33:30 CEST 2011


Let us work backward. The pic_onscr() fails because lda_result does not
exist. lda_result does not exist because your lda() fails. Your lda() fails
because "Error in lda.default(x, grouping, ...) : 
  variables  1  3  5  8 10 15 17 20 27 29 34 appear to be constant within
groups" This indicates that lda_data in lda(lda_data,groups) is constant for
at least some of the groups. This would happen, for example, if certain
groups have only one observation. You will have to remove those groups for
which lda_data is constant or aggregate them to larger groups.

HTH,
Daniel


kaslah wrote:
> 
> hello,
> i already include the error in blue color word.
> i hope it can help you to understand my question.
> if not burden you, please give me a guide how to correct the error or
> maybe you 
> can correct the coding cause error.
> thank you.
> 
> 
> 
>> #    lda.r
>> #
>> #    Author:    Amsha Nahid, Jairus Bowne, Gerard Murray
>> #    Purpose:    Perform Linear Discriminant Analysis (LDA)
>> #
>> #    Input:    Data matrix as specified in Data-matrix-format.pdf
>> #    Output:    LDA plot
>> #
>> #    Notes:    Missing values (if any) are replaced by the half of the
>> lowest
>> #              value in the entire data matrix.
>> 
>> 
>> #
>> #    Load necessary libraries, and install them if they are missing
>> #
>> tryCatch(library(MASS), error=function(err)
> +     # if this produces an error:
> +     install.packages("MASS",repos="http://cran.ms.unimelb.edu.au/"))
>> 
>> #
>> #    Prepare the data matrix
>> #
>> # Read in the .csv file
>> data<-read.csv("C:/Users/nadya/Desktop/praktikal UTM/TASK2/new(40data)S2
>> 100 
>>EMS EPI 300-399.csv", sep=",", row.names=1, header=TRUE)
>> # Get groups information
>> groups<-data[,1]
>> # Remove groups for data processing
>> lda_data<-data[,-1]
>> # Replace any missing values (see Notes)
>> lda_data[is.na(lda_data)]<-0.5*(min(lda_data,na.rm=TRUE))
>> 
>> #
>> #    Perform the LDA
>> #
>> lda_result<-lda(lda_data,groups)
> Error in lda.default(x, grouping, ...) : 
>   variables  1  3  5  8 10 15 17 20 27 29 34 appear to be constant within
> groups
>> 
>> #
>> #    Generate the figures (on screen)
>> #
>> #    Image generation - function definition
>> pic_onscr<-function(matrix, title, cex_val=1)
> +     {x11()
> +     par(mgp=c(5,2,0),                           # axis margins
> +                                                 # (title, labels, line)
> +         mar=c(7,4,4,2),                         # plot margins (b,l,t,r)
> +         las=1)                                  # horizontal labels
> +     plot(matrix,                                # data to plot
> +         cex=cex_val,                            # font size
> +         dimen=2                                 # dimensions to plot
> +         )
> +     title(main=title)                           # title of plot
> +     }
>> # Plot LDA scores with sample names
>> pic_onscr(lda_result,"Linear Discriminant Analysis")
> Error in plot(matrix, cex = cex_val, dimen = 2) : 
>   error in evaluating the argument 'x' in selecting a method for function 
> 'plot': Error: object 'lda_result' not found
>> # For plotting with larger font size, use a different value of cex:
>> # pic_onscr(lda_result, "LDA Plot", dimen=2, cex=3)
>> 
>> #
>> #    Generate figures as image files
>> #
>> #    (Uncomment blocks as necessary)
>> 
>> ##### jpeg #####
>> # pic_jpg<-function(filename, matrix, title, cex_val=1)
>> #     {# Start jpeg device with basic settings
>> #     jpeg(filename,
>> #         quality=100,                            # image quality
>> (percent)
>> #         bg="white",                             # background colour
>> #         res=300,                                # image resolution
>> (dpi)
>> #         units="in", width=8.3, height=5.8       # image dimensions
>> (inches)
>> #         )
>> #     par(mgp=c(5,2,0),                           # axis margins 
>> #                                                 #  (title, labels,
>> line)
>> #         mar=c(7,4,4,2),                         # plot margins
>> (b,l,t,r)
>> #         las=1                                   # horizontal labels
>> #         )
>> #     # Draw the plot
>> #     plot(matrix,                                # data to plot
>> #         cex=cex_val,                            # font size
>> #         dimen=2                                 # dimensions to plot
>> #         )
>> #     title(main=title)                           # title of plot
>> # 
>> #     dev.off()
>> #     }
>> # pic_jpg("LDA.jpg", lda_result, "Linear Discriminant Analysis")
>> ##### end jpeg #####
>> 
>> ##### png #####
>> # pic_png<-function(filename, matrix, title, cex_val=1)
>> #     {# Start png device with basic settings
>> #     png(filename,
>> #         bg="white",                             # background colour
>> #         res=300,                                # image resolution
>> (dpi)
>> #         units="in", width=8.3, height=5.8       # image dimensions
>> (inches)
>> #         )
>> #     par(mgp=c(5,2,0),                           # axis margins 
>> #                                                 #  (title, labels,
>> line)
>> #         mar=c(7,4,4,2),                         # plot margins
>> (b,l,t,r)
>> #         las=1                                   # horizontal labels
>> #         )
>> #     # Draw the plot
>> #     plot(matrix,                                # data to plot
>> #         cex=cex_val,                            # font size
>> #         dimen=2                                 # dimensions to plot
>> #         )
>> #     title(main=title)                           # title of plot
>> # 
>> #     dev.off()
>> #     }
>> # pic_png("LDA.png", lda_result, "Linear Discriminant Analysis")
>> ##### end png #####
>> 
>> ##### tiff #####
>> # pic_tiff<-function(filename, matrix, title, cex_val=1)
>> #     {# Start tiff device with basic settings
>> #     tiff(filename,
>> #         bg="white",                             # background colour
>> #         res=300,                                # image resolution
>> (dpi)
>> #         units="in", width=8.3, height=5.8,      # image dimensions
>> (inches)
>> #         compression="none"                      # image compression 
>> #                                                 #  (one of none, lzw,
>> zip)
>> #         )
>> #     par(mgp=c(5,2,0),                           # axis margins 
>> #                                                 #  (title, labels,
>> line)
>> #         mar=c(7,4,4,2),                         # plot margins
>> (b,l,t,r)
>> #         las=1                                   # horizontal labels
>> #         )
>> #     # Draw the plot
>> #     plot(matrix,                                # data to plot
>> #         cex=cex_val,                            # font size
>> #         dimen=2                                 # dimensions to plot
>> #         )
>> #     title(main=title)                           # title of plot
>> # 
>> #     dev.off()
>> #     }
>> # pic_tiff("LDA.tif", lda_result, "Linear Discriminant Analysis")
>> ##### end tiff #####
>> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

--
View this message in context: http://r.789695.n4.nabble.com/no-subject-tp3613275p3613392.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list