mdc
2011-Feb-10 17:40 UTC
[R] Rioja package, creating transfer function, WA, "Error in FUN"
Hi, I am a new R user and am trying to construct a palaeoenvironmental transfer function (weighted averaging method) using the package rioja. I've managed to insert the two matrices (the species abundance and the environmental data) and have assigned them to the y and x values respectively. When I try and enter the 'WA' function though, I get an 'Error in FUN' message (see below for full values). Alas, I do not know what this means and have struggled to find similar problems to this online. Is there a step I've missed out between assigning the matrices and the WA function?> SWED=odbcConnectExcel(file.choose()) (SWED is the environmental data > file) > sqlTables(SWED) > Env=sqlFetch(SWED, "Sheet1") > odbcClose(SWED) > EnvSampleId WTD Moisture pH EC 1 "N1_1" "20" "91.72700" "3.496674" " 85.02688" 2 "N1_2" " 2" "93.88913" "3.550794" " 85.69465" 3 "N1_3" "26" "90.30269" "3.948559" "113.19206" 4 "N1_4" " 5" "94.14427" "3.697213" " 48.56375" 5 "N1_5" "30" "90.04269" "3.745020" "108.57278" .... 90 "GAL_15" "70" "94.07849" "3.777932" " 66.77673"> STEST=odbcConnectExcel(file.choose()) > sqlTables(STEST) (STEST is the > species abundance file) > Spe=sqlFetch(STEST, "Sheet8") > odbcClose(STEST) > Spe(The species data contains the abundance of 32 species over 90 sites, set out like this) F1 AmpFlav AmpWri ArcCat ArcDis 1 N1_1 22.2929936 0.0000000 0.0000000 0.0000000 2 N1_2 30.9677419 0.0000000 0.0000000 3.2258065> library(rioja) > y <-as.matrix(Spe) > x <-as.matrix(Env)> WA(y, x, tolDW = FALSE, use.N2=TRUE, check.data=TRUE, lean=FALSE) (the > command from the WA section of the rioja booklet)Error in FUN(newX[, i], ...) : invalid 'type' (character) of argument Any help would be most appreciated, Best wishes, Matthew -- View this message in context: http://r.789695.n4.nabble.com/Rioja-package-creating-transfer-function-WA-Error-in-FUN-tp3299636p3299636.html Sent from the R help mailing list archive at Nabble.com.
Peter Ehlers
2011-Feb-11 00:42 UTC
[R] Rioja package, creating transfer function, WA, "Error in FUN"
On 2011-02-10 09:40, mdc wrote:> > Hi, I am a new R user and am trying to construct a palaeoenvironmental > transfer function (weighted averaging method) using the package rioja. > I've managed to insert the two matrices (the species abundance and the > environmental data) and have assigned them to the y and x values > respectively. When I try and enter the 'WA' function though, I get an 'Error > in FUN' message (see below for full values). Alas, I do not know what this > means and have struggled to find similar problems to this online. Is there a > step I've missed out between assigning the matrices and the WA function? > >> SWED=odbcConnectExcel(file.choose()) (SWED is the environmental data >> file) >> sqlTables(SWED) >> Env=sqlFetch(SWED, "Sheet1") >> odbcClose(SWED) >> Env > > SampleId WTD Moisture pH EC > 1 "N1_1" "20" "91.72700" "3.496674" " 85.02688" > 2 "N1_2" " 2" "93.88913" "3.550794" " 85.69465" > 3 "N1_3" "26" "90.30269" "3.948559" "113.19206" > 4 "N1_4" " 5" "94.14427" "3.697213" " 48.56375" > 5 "N1_5" "30" "90.04269" "3.745020" "108.57278" > .... > 90 "GAL_15" "70" "94.07849" "3.777932" " 66.77673" > > >> STEST=odbcConnectExcel(file.choose()) >> sqlTables(STEST) (STEST is the >> species abundance file) >> Spe=sqlFetch(STEST, "Sheet8") >> odbcClose(STEST) >> Spe > > (The species data contains the abundance of 32 species over 90 sites, set > out like this) > F1 AmpFlav AmpWri ArcCat ArcDis > 1 N1_1 22.2929936 0.0000000 0.0000000 0.0000000 > 2 N1_2 30.9677419 0.0000000 0.0000000 3.2258065 > >> library(rioja) >> y<-as.matrix(Spe) >> x<-as.matrix(Env) > >> WA(y, x, tolDW = FALSE, use.N2=TRUE, check.data=TRUE, lean=FALSE) (the >> command from the WA section of the rioja booklet) > Error in FUN(newX[, i], ...) : invalid 'type' (character) of argumentWell, the error message is fairly clear: you're feeding in something of type 'character' where something else (presumably) numeric is wanted. I don't use rioja, but a quick glance at the documentation for WA shows that x should be 'a vector of environmental values to be modelled'. The example uses pH which is almost surely not a character vector. Your x is a *matrix* of *character* values. Possibly, you want to pull, say, pH out of your Env, convert to numeric and try that. Ditto for the other variables. If the above is total nonsense, please forgive my rioja ignorance and wait for more cogent advice from someone more knowledgeable than I. Peter Ehlers> > > Any help would be most appreciated, > Best wishes, > Matthew
Gavin Simpson
2011-Mar-02 14:39 UTC
[R] Rioja package, creating transfer function, WA, "Error in FUN"
On Thu, 2011-02-10 at 09:40 -0800, mdc wrote:> Hi, I am a new R user and am trying to construct a palaeoenvironmental > transfer function (weighted averaging method) using the package rioja. > I've managed to insert the two matrices (the species abundance and the > environmental data) and have assigned them to the y and x values > respectively. When I try and enter the 'WA' function though, I get an 'Error > in FUN' message (see below for full values). Alas, I do not know what this > means and have struggled to find similar problems to this online. Is there a > step I've missed out between assigning the matrices and the WA function? > > > SWED=odbcConnectExcel(file.choose()) (SWED is the environmental data > > file) > > sqlTables(SWED) > > Env=sqlFetch(SWED, "Sheet1") > > odbcClose(SWED) > > Env > > SampleId WTD Moisture pH EC > 1 "N1_1" "20" "91.72700" "3.496674" " 85.02688" > 2 "N1_2" " 2" "93.88913" "3.550794" " 85.69465" > 3 "N1_3" "26" "90.30269" "3.948559" "113.19206" > 4 "N1_4" " 5" "94.14427" "3.697213" " 48.56375" > 5 "N1_5" "30" "90.04269" "3.745020" "108.57278" > .... > 90 "GAL_15" "70" "94.07849" "3.777932" " 66.77673"That's your problem, the odbc stuff has read the data in as characters. CSV would be a lot simpler, just save your excel sheets as CSV files and read them in with: Env <- read.csv("my_excel_sheet.csv", row.names = 1) etc... where my_excel_sheet.csv is the name of your saved csv file or just use: Env <- read.csv(file.choose(), row.names = 1) if finding files via the GUI is helpful to you. It is odd that the species data set has been read in OK though - I say OK, but you still need to get the F1 column out of the species data and set it as the row names of your data. Sorry I'm coming to this late; I've been away and not really following the list for a few weeks. If you can't get things working, contact me off list and send the Excel files and I'll send back a script that will load the files and do the WA for you to look at. HTH G> > > STEST=odbcConnectExcel(file.choose()) > > sqlTables(STEST) (STEST is the > > species abundance file) > > Spe=sqlFetch(STEST, "Sheet8") > > odbcClose(STEST) > > Spe > > (The species data contains the abundance of 32 species over 90 sites, set > out like this) > F1 AmpFlav AmpWri ArcCat ArcDis > 1 N1_1 22.2929936 0.0000000 0.0000000 0.0000000 > 2 N1_2 30.9677419 0.0000000 0.0000000 3.2258065 > > > library(rioja) > > y <-as.matrix(Spe) > > x <-as.matrix(Env) > > > WA(y, x, tolDW = FALSE, use.N2=TRUE, check.data=TRUE, lean=FALSE) (the > > command from the WA section of the rioja booklet) > Error in FUN(newX[, i], ...) : invalid 'type' (character) of argument > > > Any help would be most appreciated, > Best wishes, > Matthew-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%