Change vegan::adonis class to lm?
I am running a perm-manova using the
adonis2 function in
vegan package. I have a significant interaction in my model, so would like to perform tukey-adjusted comparisons for the interaction using the
lsmeans accepts many model classes, it does not accept the class of the
adonis object (
 "anova.cca" "anova" "data.frame").
Is there a way I can coerce my
adonis object to an
manova object (or any other class accepted by
lsmeans) so that I can use this function? Thank you
library(vegan) library(lsmeans) data(dune) data(dune.env) man<-adonis2(dune ~ Management*A1, data = dune.env) lsmeans(man,pairwise ~ Management:A1,adjust="tukey") Error in ref.grid(object = list(Df = c(3, 1, 3, 12), SumOfSqs = c(1.46859175179317, : Can't handle an object of class “anova.cca” Use help("models", package = "lsmeans") for information on supported models.
See also questions close to this topic
removing points while keeping the line in a scatter plot
How do I remove the points from a scatter plot created by below code ? I just wanted to keep the smoothed line.
ggplot(mtcars, aes(x=wt, y=mpg, color=cyl, shape=cyl)) + geom_point() + geom_smooth(method=lm)
Pairing truncated character into a dataframe
I have a chr[1:10] truncated data and each line is organized in such way and some rows don't have the same length:
 "\nA B C D E"  "\n1 3 4 5"  "\nF G H"  "\n6 7 8"
Is there anyway that I can make pair them up in a dataframe like the example below:
Col1 Col2 A 1 B C 3 D 4 E 5 F 6 G 7
wilcoxon.test: how do you skip NA data
I have a csv file with two data sets that I would like to compare, variable 1 (first column) has 21 data points and variable 2 has 18 data points. How do I ignore the NA data?
This is what I have right now: wilcox.test(mydata$Old_0.5, mydata$New_0.5, alternative="two.sided")
R: Mixed ANOVA: Error() model is singular. Possible issue?
My Data frame (P.all) looks like this (138 entries) :
Agent Partner Interaction Power Mean 1680923090 1930803083 1 HP 1.5380609 1680923090 1780828011 2 LP 0.7256550 1700418014 1790316024 2 HP 1.2319399 1700801048 1770927023 1 HP 0.7041565 1700801048 1791328007 2 LP 0.5321680
I have to calculate a mixed ANOVA (2x2). The between factor is "Power" (as Low vs high power) and the within factor is "interaction" (interaction 1 vs. interaction 2). The dependant Variable is "Mean". The value for "Mean" refers to the person in the column "agent".
To calculate the ANOVA I did this:
Model <- aov(Mean ~ Power*Interaction + Error(Agent/Interaction), data = P.all) Warning message: In aov(Mean ~ Power * interaction + Error(agent/interaction), : Error() model is singular
Is the calculation correct?
I had to exclude some interactions from the data because they interacted with a "confidant" (e.g. the first interaction of Person "1700418014"). Is this the problem? Does every person have to have two interactions for a working 2x2 mixed ANOVA?
Thank you for your answers.
Edit: I deleted the single entrances which had only one interaction and now it is working. Is there another possibility without losing this data?
How can I do Repeated Measures ANOVA for correlation metrix in R
I created correlation matrix(16x16)using cor(), and I was asked to do **ANOVA with repeated measures on it.
I found some examples, but these examples used labeled data. Some works did linear regression before doing ANOVA analysis. For me, it is just matrix of numeric values. I am asked to find p-value.
Can any one help me to do that?
Why doesn't R unique() work with fitted values extracted from lm() objects?
Unique finds unique values of a vector.
If I have a data frame:
test_data <- data.frame(x = c(rep(1.00050239485720394857,4), 1.00050239485720394854,rep(2.0002230948570293845,5),rep(3.0005903847502398475,5)), y = c(rep(4.00423409872345,5),rep(2.034532039485722,5),rep(1.1234152304957,5))) sapply(test_data,unique)
x y [1,] 1.000502 4.004234 [2,] 2.000223 2.034532 [3,] 3.000590 1.123415
But say I fit an lm() or aov() object and then try to find unique fitted values():
set.seed(123) y = rf(100,50,3,3) x1 <- factor(c(rep("blue",25), rep("green",25), rep("orange",25), rep("purple",25))) bsFit <- aov(y ~ x1) unique(bsFit$fitted.values)
 2.709076 2.709076 2.709076 2.709076 2.709076 2.709076  2.709076 4.060080 4.060080 4.060080 4.060080 3.314801  3.314801 3.314801 3.314801 1.960280 1.960280 1.960280  1.960280 1.960280
There are clearly duplicates here.
Remove score legend form ggvegan plot
I conducted a CCA using the vegan package and now I am plotting the results using ggvegans autoplot function. The resulting plot contains a legend, which shows the displayed scores. Is it possible to remove this legend form the plot?
autoplot(spe.cca, axes = c(1, 2), geom = c("text"), layers = c("species", "biplot"), title = "CCA of unimodal responses" , legend.position = "none") + theme_gray()
Result of nesting two random factor within an interaction term in vegan vs permanova
I have a mixed design that includes two fixed factors (A and B) and two random factors (C and D) that are nested to the interaction. I ran this design in Primer+Permanova and I want to replicate it in R using adonis, from the vegan package. The problem is that I'm obtaining a different number of degrees of freedom in the residuals. I used the formula:
Y ~ A*B + ((A*B)/C) + ((A*B)/D)
All the degrees of freedom coincide but the rest of the calculations (sums of squares, pseudo-F, p-values) are totally different. In the past, I've compared simpler models and obtained the same results. What could I be missing here?
How to do a rarefaction in r?
I have three different groups of vegetation. I want to do a rarefaction of species richness for these groups and and based on it create a Venn diagram. But I have no idea how to do that. Should I also do a rarefaction for overlapped areas? Any ideas? Many many thanks in advance.
Error in lme model and lsmeans output
I'm running an LME model with the lme4 package and then follow up pairwise comparisons with lsmeans package.
Here is my code:
lmer_full <- lmer (VOT ~ Place*Laryngeal + (1+Place+Laryngeal|Sp), data = LME,control=lmerControl(optCtrl=list(maxfun=50000))) lsmeans (lmer_full, pairwise~Laryngeal|Place)
However, I get the following error message after running the lmer:
fixed-effect model matrix is rank deficient so dropping 1 column / coefficient
1: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : unable to evaluate scaled gradient
2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : Model failed to converge: degenerate Hessian with 1 negative eigenvalues
Then another error after running the lsmeans:
base::chol2inv(x, ...) : 'a'must be a numeric matrix
Here is the structure of my data:
I would really appreciate if someone can tell me what's wrong with the model.
lsmeans and continuous time
I would like to have your help on this problem. I wish to express the evolution of a quality of life score over the time with adjustment on clinical factors. I work on a cohort of more than 1000 patients and a quality of life form was delivered every 3 months. Time is considered continuous as patients did not fill the form exactly at same time.
Here is my problem I used a linear mixed model with fixed factors (the sex and the prognosis). I would like to obtain the average score at 3, 6, 9 and 12 months from this model. I used the lsmeans function but the score obtained corresponds to average time. How can I get average scores from my model at these 4 different times? You will find below my code and the result I get with lsmeans
mod_mix2 <- lme(score_utilite~delai+prono1+sex1,random = ~ delai|numero_patient, data = qdv,na.action=na.omit,method="ML") lsmeans(mod_mix2, specs ="delai")
$lsmeans delai lsmean SE df lower.CL upper.CL 10.21976 0.8145542 0.005835597 1016 0.803103 0.8260054
Results are averaged over the levels of: prono1, sex1 Confidence level used: 0.95
$contrasts contrast estimate SE df z.ratio p.value (nothing) nonEst NA NA NA NA
Results are averaged over the levels of: prono1, sex1
Thank you very much
Error in base::chol2inv(x, ...)
I am doing a LME. Afterwards I add:
lsmeans(lmer, pairwise ~ eye_status)
and I get this error:
Error in base::chol2inv(x, ...) : 'a' has to be a numeric matrix Also: Warning message: In if (REML) p else 0L : condition length > 1 only the first element will be used
Could you please help me to solve it? Any idea of where is the mistake? Thanks Adriana.
Unable to run Mancova in Matlab, what is the alternative?
I have 4 different conditions that conducted within subjects, and each condition has 40 trials. I want to run an Mancova test in matlab but I could not find it in the documentation. Basically, Mancova is same as Manova but it gives you chance to add two or more covariates which may influence your DV. I want to see how an individual's political orientation and religion affects his/her behavior in conditions after checking their other demographics or some psychological test scores.
Is there any way to do it in Matlab or should I run Manova and chi-square tests separately etc?
Also when I try to use manova1 function in matlab it gives an error which states it is an undefined function.
>> manovatrial= manova1(1,A.resp11) Undefined function or variable 'manova1'.
Thanks in advance for your commments.
Matlab mutliple anova analysis
I hope you are all good! I have a question about anova test in Matlab. My data has 150 subjects and each subject participate 4 different conditions. Each conditions has 40 trials. I want to run Anova for my data. Basically, I want to see the avarage behavior in each conditions and also I want to put participants into their religion groups. I suppose I have to do it separately. Which function is more suitable for my data?
All of my data are saved as cells. Ex: cond1 150x40 cond2: 150x40 etc...
thanks in advance!
Change in insect community over time using PERMANOVA, should i include nested effect? What is the best code
I have a data set of an insect community composition (17 insect species, raw abundance data, sampled 5 times over 60 days within 24 tanks( 4 replicates). There were 3 treatments( free fish, caged fish, absent fish) involved with 2 levels (open and closed tanks) for each treatment. And my question is does community composition and diversity change over time? And if so, are these changes different under different treatments?
I decided to answer this question by using PERMANOVA. My next question is picking the best code for it. Because i have to take into account change in time under different treatments and that i possibly have a nested effect (different levels of opened and closed tanks), i'm confused on which symbols to use to address my nestedness as i've read that i can just use the term "strata= group" or just put "/" into my formula
(X~ treatment*time ; x~treatment/time ; or x~ treatment , strata = time)
My codes are:
fisheats<-adonis(tfish~tfish$fishtreatment*tfish$Time_days, method = "bray", permutations = 999)
fishnest<-adonis(tfish~tfish$fishtreatment/tfish$Time_days, method = "bray", permutations = 999)
fisheats2<-adonis(tfish~tfish$fishtreatment, method = "bray", permutations = 999, strata = tfish$Time_days)
Which code is the preferred code to answer my question?