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

2016-10-18 Thread PIKAL Petr
Hi

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Kirsten
> Green
> Sent: Tuesday, October 18, 2016 9:27 PM
> To: David L Carlson 
> Cc: r-help@r-project.org
> Subject: Re: [R] MDS, line of best fit, and id of variables
>
> David,
>
> I have run the str() function and all my data is int (integer). So I am 
> trying to

It is strange. Error from metaMDS(mortdata) indicates that you have some 
nonnumeric data in your data frame which definitely should be indicated by str.

e.g.
str(data.frame(a=factor(1:5), b=rnorm(5)))
'data.frame':   5 obs. of  2 variables:
 $ a: Factor w/ 5 levels "1","2","3","4",..: 1 2 3 4 5
 $ b: num  -0.201 -1.639 0.108 0.259 -1.33

> change it to numeric using:
> str(mortdata)
> class(mortdata)
> is.numeric(mortdata)
> mortdata.num <- as.numeric(data.frame(mortdata))

As Bert said you should spent some time to evaluate distinctions among various 
object types. For making data frame numeric you need to use sapply.

str(sapply(data.frame(a=factor(1:5), b=rnorm(5)), as.numeric))
 num [1:5, 1:2] 1 2 3 4 5 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:2] "a" "b"

however if you have factors in your data frame you could get some nasty 
surprise with such simple approach and it also changes data.frame to matrix.

Cheers
Petr

>
> But I keep getting an error: > mortdata.num <- as.numeric(data.frame(
> mortdata))
> Error: (list) object cannot be coerced to type 'double
>
> On Tue, Oct 18, 2016 at 1:23 PM, David L Carlson 
> wrote:
>
> > 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-boun...@r-project.org] On Behalf Of
> > Kirsten Green
> > Sent: Tuesday, October 18, 2016 12:28 PM
> > To: r-help@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=&

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

2016-10-18 Thread Bert Gunter
You need to spend time with an R tutorial or two. Your error is due to
ignorance of basic R data structures.

Bert

On Oct 18, 2016 10:48 PM, "Kirsten Green"  wrote:

> David,
>
> I have run the str() function and all my data is int (integer). So I am
> trying to change it to numeric using:
> str(mortdata)
> class(mortdata)
> is.numeric(mortdata)
> mortdata.num <- as.numeric(data.frame(mortdata))
>
> But I keep getting an error: > mortdata.num <- as.numeric(data.frame(
> mortdata))
> Error: (list) object cannot be coerced to type 'double
>
> On Tue, Oct 18, 2016 at 1:23 PM, David L Carlson 
> wrote:
>
> > 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-boun...@r-project.org] On Behalf Of Kirsten
> > Green
> > Sent: Tuesday, October 18, 2016 12:28 PM
> > To: r-help@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*
> > kagbo...@gmail.com
> > 916-712-5193
> > __
> > R-help@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.
> >
>
>
>
> --
> *Kirsten Green*
> kagbo...@gmail.com
> 916-712-5193
>
> [[alternative HTML version deleted]]
>
> __
> R-help@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.

[[alternative HTML version deleted]]

__
R-help@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.

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

2016-10-18 Thread Kirsten Green
David,

I have run the str() function and all my data is int (integer). So I am
trying to change it to numeric using:
str(mortdata)
class(mortdata)
is.numeric(mortdata)
mortdata.num <- as.numeric(data.frame(mortdata))

But I keep getting an error: > mortdata.num <- as.numeric(data.frame(
mortdata))
Error: (list) object cannot be coerced to type 'double

On Tue, Oct 18, 2016 at 1:23 PM, David L Carlson  wrote:

> 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-boun...@r-project.org] On Behalf Of Kirsten
> Green
> Sent: Tuesday, October 18, 2016 12:28 PM
> To: r-help@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*
> kagbo...@gmail.com
> 916-712-5193
> __
> R-help@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.
>



-- 
*Kirsten Green*
kagbo...@gmail.com
916-712-5193

[[alternative HTML version deleted]]

__
R-help@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.

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

2016-10-18 Thread David L Carlson
You do not need to change it to numeric if it is integer. But if you want to 
change it, you need to follow the example I included and use sapply(). 

Here is my effort to replicate your error. Since I'm using random data, it 
fails to converge, but I do not get the error message you are getting. This is 
the best I can do since you have not given us reproducible data. 

> set.seed(42)
> mortdata <- data.frame(matrix(sample(0:1, 28*27, replace=TRUE), 28, 27))
> dim(mortdata)
[1] 28 27
> library(vegan)
Loading required package: permute
Loading required package: lattice
This is vegan 2.4-1
> sapply(mortdata, type)
Error in match.fun(FUN) : object 'type' not found
> sapply(mortdata, class)  # Is everything numeric (which includes integer)?
   X1X2X3X4X5X6X7X8 
   X9 
"integer" "integer" "integer" "integer" "integer" "integer" "integer" "integer" 
"integer" 
  X10   X11   X12   X13   X14   X15   X16   X17 
  X18 
"integer" "integer" "integer" "integer" "integer" "integer" "integer" "integer" 
"integer" 
  X19   X20   X21   X22   X23   X24   X25   X26 
  X27 
"integer" "integer" "integer" "integer" "integer" "integer" "integer" "integer" 
"integer" 
> mortdata.mds <- metaMDS(mortdata)
. . . Many messages 
... New best solution
... Procrustes: rmse 0.07861438  max resid 0.2210256 
Run 18 stress 0.277969 
Run 19 stress 0.2633298 
Run 20 stress 0.2838487 
*** No convergence -- monoMDS stopping criteria:
    20: stress ratio > sratmax

---------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352




From: Kirsten Green [mailto:kagbo...@gmail.com] 
Sent: Tuesday, October 18, 2016 2:27 PM
To: David L Carlson
Cc: r-help@r-project.org
Subject: Re: [R] MDS, line of best fit, and id of variables

David,

I have run the str() function and all my data is int (integer). So I am trying 
to change it to numeric using:
str(mortdata)
class(mortdata)
is.numeric(mortdata)
mortdata.num <- as.numeric(data.frame(mortdata))

But I keep getting an error: > mortdata.num <- as.numeric(data.frame(mortdata))
Error: (list) object cannot be coerced to type 'double

On Tue, Oct 18, 2016 at 1:23 PM, David L Carlson  wrote:
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-boun...@r-project.org] On Behalf Of Kirsten Green
Sent: Tuesday, October 18, 2016 12:28 PM
To: r-help@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

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

2016-10-18 Thread David L Carlson
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-boun...@r-project.org] On Behalf Of Kirsten Green
Sent: Tuesday, October 18, 2016 12:28 PM
To: r-help@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*
kagbo...@gmail.com
916-712-5193
__
R-help@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.
__
R-help@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.