[R] MDS, line of best fit, and id of variables

David L Carlson dcarlson at tamu.edu
Tue Oct 18 21:23:53 CEST 2016


What do you get with str(mortdata)? The error message indicates that at least one of the variables is not numeric and the second suggests it is a factor. You said the values were coded binomially, but they must be numeric, e.g. 0, 1 and not "Present" "Absent" or something like that. If they are all factors, something like

mortdata1 <- sapply(mortdata, as.numeric)-1

would convert factor levels of 1 and 2 to 0 and 1.
-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352

-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Kirsten Green
Sent: Tuesday, October 18, 2016 12:28 PM
To: r-help at r-project.org
Subject: [R] MDS, line of best fit, and id of variables

Hi,

I have created a dataset that includes 28 rows (burials) and 27 columns
(variables) that are coded binomially. I have gotten metaMDS to run in the
pst but now can't seem to get it run at all.
Error message:
> mortdata.mds <- metaMDS(mortdata)
Error in FUN(X[[i]], ...) :
  only defined on a data frame with all numeric variables
In addition: Warning message:
In Ops.factor(left, right) : ‘<’ not meaningful for factors

I'd like to create a 3D MDS plot and add the line of best fit for the 3
dimensions (3 variables). I am also trying to figure out, or understand,
which variables are causing the variation.

I ran PCA and it told me that with 3 variables approximately 50% of the
data variation is explained. So I assumed that meant that running MDS in 3
dimensions would show me 3 variables causing the variation but I can't get
that to work.

Here is my code so far (i've also attached it to the email):

mortdata<-read.csv("Table5.5.csv", header=TRUE)
mortdata
row.names(mortdata) <- mortdata[,1]
mortdata <- mortdata[,-1]
mortdata

mortdata.mds <- metaMDS(mortdata)
mortdata.mds.alt <- metaMDS(mortdata, distance="euclidean", k=3, trymax=50,
      autotransform=FALSE, noshare=FALSE)


*object = mortdata.mds.alt

names(mortdata.mds.alt)

mortdata.mds.alt
summary(mortdata.mds.alt)

*stress plot
stressplot(mortdata.mds.alt)

x <- mortdata.mds.alt$species
y <- mortdata.mds.alt$points
na.exclude(mortdata.mds.alt)
vScoresScale <- scale(, center = TRUE, scale = TRUE)


plot(mortdata.mds.alt)
plot(mortdata.mds.alt, type="t")

*multiple linear regression model
lm(formula = x ~ y)
abline(lm(x ~ y), col="red")


*scatterplot3D
library(scatterplot3d)
attach(mortdata.mds.alt)
scatterplot3d(mortdata.mds.alt, x="sampleScores", y="variableScores",
main="3D Scatterplot")

Any help would be greatly appreciated. I can also send the dataset if that
helps.

-- 
*Kirsten Green*
kagbones at gmail.com
916-712-5193
______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


More information about the R-help mailing list