[R] confusion matrix error
Hi, this is my R-script I need to make a confusion matrix but the last row return me an error require(mixOmics) require(SDMTools) file - C:\\data.txt d - read.table(file, header=T, row.names = NULL) X - as.matrix(d[,2:11]) Y - as.factor(d[,1]) i - 1 samp - sample(1:3, nrow(X), replace = TRUE) # Creation of a list of the same size as X test - which(samp == i) # Search which column in samp has a value of 1 train - setdiff(1:nrow(X), test) # Keeping the column that are not in test #PLS-DA plsda.train - plsda(X[train, ], Y[train], ncomp = 10) test.predict - predict(plsda.train, X[test, ], method = class.dist) confusion.matrix(test.predict, Y[-train]) Error in confusion.matrix(test.predict, Y[-train]) : this requires the same number of observed predicted values I have no idea why it don't work Thank you for help -- View this message in context: http://r.789695.n4.nabble.com/confusion-matrix-error-tp3568913p3568913.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] PLSR error
Hi, this is my R-Script library(pls) file - C:\\TXT\\brix.txt d - as.matrix(read.table(file, header=T, sep=,, row.names = NULL)) plsdata - data.frame(NIR=c(1:nrow(X))) plsdata$NIR - I(d[,3:603]) plsdata$Brix - d[,2] results - plsr(Brix ~ NIR, data=plsdata) after the last string i have this error results - plsr(Brix ~ NIR, data=plsdata) Error in `[[-.data.frame`(`*tmp*`, i, value = c(302053L, 305882L, 292704L, : replacement has 448346 rows, data has 746 In addition: Warning message: In model.matrix.default(mt, mf) : variable 'Brix' converted to a factor the data table have this structure str(plsdata) 'data.frame': 746 obs. of 2 variables: $ NIR : 'AsIs' chr [1:746, 1:601] 0.0011030396 0.0013019324 0.0005979965 0.0012952804 ... ..- attr(*, dimnames)=List of 2 .. ..$ : NULL .. ..$ : chr X1100.0 X1102.0 X1104.0 X1106.0 ... $ Brix: chr 24.4 24.8 24.7 20.1 ... where am I wrong? thanks for help -- View this message in context: http://r.789695.n4.nabble.com/PLSR-error-tp3519805p3519805.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] test
Thank you all for the precious help. Finally i could start the writing of a first part of my script, but now i have a new question for you. Need i to repeat the write.table portion for all the 15 lines or can i use a short cut? Example: file.open - C:\\test.txt file.save - C:\\results.txt my.data - read.table(file, header=T) library(plyr) write.table(ddply(my.data, .(Thesis, Day), function(x){ Baseline - unlist(x[1, c(A, B, C)]) data.frame(t(apply(x[-1, c(A, B, C)], 1, function(z){z - Baseline}))) }), file = file.save, row.names = F) write.table(ddply(my.data, .(Thesis, Day), function(x){ Baseline - unlist(x[2, c(A, B, C)]) data.frame(t(apply(x[-1:-2, c(A, B, C)], 1, function(z){z - Baseline}))) }), file = file.save, append = T, row.names = F, col.names = F) etc etc Thanks again for the help. Best regards, Roberto. -- View this message in context: http://r.789695.n4.nabble.com/Comparison-of-numbers-in-a-table-tp3217329p3218524.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] test
Hi, i have that table Thesis Day A B C 1 0 83.43 90.15 22.97 1 0 85.50 94.97 16.62 1 0 83.36 95.38 20.70 1 0 84.47 92.16 23.58 1 0 83.98 95.33 19.39 1 0 82.86 93.78 24.55 1 0 83.39 92.67 19.56 1 0 85.17 95.24 17.95 1 0 81.62 93.32 28.49 1 0 82.99 92.85 19.73 1 0 81.11 95.67 27.20 1 0 83.39 94.69 16.51 1 0 79.56 89.87 30.39 1 0 80.54 93.32 21.76 1 0 82.11 92.58 22.17 1 14 85.65 94.00 19.19 1 14 85.06 92.44 20.44 1 14 83.97 91.39 24.38 1 14 84.61 91.97 19.44 1 14 85.13 90.59 25.30 1 14 84.81 91.01 19.80 1 14 84.52 94.06 18.77 1 14 84.30 94.49 24.90 1 14 84.74 91.32 20.35 1 14 84.08 94.12 22.96 1 14 84.50 94.25 19.95 1 14 84.02 94.74 20.35 1 14 85.30 92.82 21.12 1 14 85.08 91.14 24.16 1 14 85.21 95.69 18.17 etc etc etc etc etc 2 0 83.43 90.15 22.97 2 0 85.50 94.97 16.62 2 0 83.36 95.38 20.70 2 0 84.47 92.16 23.58 2 0 83.98 95.33 19.39 2 0 82.86 93.78 24.55 2 0 83.39 92.67 19.56 2 0 85.17 95.24 17.95 2 0 81.62 93.32 28.49 2 0 82.99 92.85 19.73 2 0 81.11 95.67 27.20 2 0 83.39 94.69 16.51 2 0 79.56 89.87 30.39 2 0 80.54 93.32 21.76 2 0 82.11 92.58 22.17 2 14 84.48 91.23 20.44 2 14 85.22 93.08 22.54 2 14 83.89 92.74 25.11 etc etc etc etc etc I need to subtract from every number the other numbers of the same thesis and same day. Example: A(row1) - A (row2) (same for B and C) A(row1) - A (row3) etc until the last Thesis 1 and Day 0 A(row2) - A (row3) etc etc until the last Thesis 1 and Day 0 Same for the others theses and days. How can i do that? Sorry for my english. -- View this message in context: http://r.789695.n4.nabble.com/test-tp3217329p3217329.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] less than or equal to glyph
If i insert \u2264 inside the text, like this lsd_label - LSD (P \u2264 0.05) = the result is LSD (P = 0.05) = instead LSD (P ≤ 0.05) = how can i solve this problem? Thanks. -- View this message in context: http://r.789695.n4.nabble.com/less-than-or-equal-to-glyph-tp3073557p3073557.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] Some questione about plot
Q1: How can i draw LSD (Least significant difference) on a plot? Like this... http://r.789695.n4.nabble.com/file/n3053430/LSD.jpg Q2: How can i draw the axis secondary scale? Thanks for help. -- View this message in context: http://r.789695.n4.nabble.com/Some-questione-about-plot-tp3053430p3053430.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] Question about readLines
Can i use readLines to extract only the linees with a specific word within? If yes, how? Tnx for help. -- View this message in context: http://r.789695.n4.nabble.com/Question-about-readLines-tp3044701p3044701.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] mean on a plot
Hi, i need to draw a plot with means of values, reading a table from datafile. Example of datafile: DaysWeight 0 178.00 0 250.00 0 242.00 0 239.00 0 223.00 0 188.00 0 237.00 0 212.00 0 273.00 0 191.00 0 173.00 0 233.00 0 227.00 0 253.00 0 232.00 4 177.00 4 249.00 4 241.00 4 238.00 4 222.00 4 188.00 4 236.00 4 211.00 4 272.00 4 190.00 4 172.00 4 232.00 4 226.00 4 252.00 4 231.00 if i use plot(Weight~Days, data=la) the result is this http://r.789695.n4.nabble.com/file/n3031068/weightm.jpg how can i draw a plot with means for each days? tnx for help :) -- View this message in context: http://r.789695.n4.nabble.com/mean-on-a-plot-tp3031068p3031068.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] mean on a plot
Perfect. Thank you Joshua. -- View this message in context: http://r.789695.n4.nabble.com/mean-on-a-plot-tp3031068p3031267.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.