I have run a simple linear regression in R with two variables and got the following relation:
y = 30000+1.95x
Which is reasonably fair. My only concern is that, practically the (0,0) point should be included in the model.
Is there any math help I can get please ?
I needed to post the data somehow... and here it is. This will give a better approach to the problem now.
There are more such data sets available. This is data collected for a marketing strategy.
The objective is to obtain a relation between sales and spend so that we can predict the spend amount that we need in order to obtain a certain amount of sales.
All help will be appreciated.
This is not an answer, but rather a comment with graphics.
I converted the month data to "elapsed months", starting with 1 as the first month, then 2, then 3 etc. This allowed me to view the data in 3D, and as you can see from the 3D scatterplot below, both Spend and Sales are related to the number of months that have passed. I also scaled the financial data in thousands so I could more easily read the plots.
I fit the data to a simple flat surface equation of the form "z = f(x,y)" as shown below, as this equation was suggested to me by the scatterplot. My fit of this data gave me the equation
Sales (thousands) = a + b * Months + c * Spend(thousands)
with fitted parameters
a = 2.1934871882483066E+02
b = 6.3389747441412403E+01
c = 1.0011902575903093E+00
for the following data:
Month Spend Sales
1 120.499 327.341
2 168.666 548.424
3 334.308 978.437
4 311.963 885.522
5 275.592 696.238
6 405.845 1268.859
7 399.824 1054.429
8 343.622 1193.147
9 619.030 1118.420
10 541.674 985.816
11 701.460 1263.009
12 957.681 1960.920
13 479.050 1240.943
14 552.718 1821.106
15 633.517 1959.944
16 527.424 2351.679
17 1050.231 2419.749
18 583.889 2104.677
19 322.356 1373.471
if you want to include the point (0,0) in your regression line this would mean setting the intercept to zero.
In R you can achieve this by
mod_nointercept <- lm(y ~ 0 + x)
In this model only beta is fitted. And alpha (i.e. the intercept is set to zero).
Related
I am using a commercial ELISA kit which contains four standards. These standards are used to create a standard curve, with optical densities from the ELISA reader on the y axis and concentrations in international units per milileter on the x axis.
I now need to use this standard curve to get concentrations for samples in which I only have the optical density readings. The ELISA kit instructions specifically state "Use “point-to-point” plotting for calculation of the standard curve by computer".
I am assuming they mean derive the value of x by seeing where y is hitting the line between the points on the standard curve and dropping down to the x axis from there. The problem is I have no idea how to do this in r (which is what I am using for my full analytical pipeline). I have searched in vain for any r packages, functions or code which correspond to "point-to-point" but can´t find anything. All the R packages that deal with ELISA data and / or standard curves (e.g. drc and ELISAtools seem to do something much more complex, i.e. fit a log model and account for inter-plate variances etc., which is not what I need.
Please note that I don´t need to visualise the standard curve - I just need a method to get the concentrations from the standard curve data based on the point-to-point line.
Here is some sample data:
# Data for standard curve:
scdt <- data.table(id = c("Cal1", "Cal2", "Cal3", "Cal4"),
conc = c(200, 100, 25, 5),
od = c(1.783, 1.395, 0.594, 0.164))
> scdt
id conc od
1: Cal1 200 1.783
2: Cal2 100 1.395
3: Cal3 25 0.594
4: Cal4 5 0.164
# Some example OD values for which I would like to derive concentration:
unknowns <- c(0.015, 0.634, 0.891, 1.510, 2.345, 3.105)
In the example values I want to solve for x, I have also included some that are outside the range covered by the standards as this also occurs in my real data from time to time. The kit manufacturer advises against reporting IU/mL for anything with an OD exceeding that of the highest standard (Cal1) which is sensible.
How can I do the R equivalent of finding x with a ruler and graph paper from the standard curve and what is this formally called? (I think one reason I might not have found anything is because "point-to-point" isn´t a mathematical term, but there must be one for this - is it interpolation?).
It sounds like you want a simple linear interpolation. This is achieved in R using the function approx. You feed it your known x values, your known y values and the new values for x for which you want the corresponding y values. (Note that it doesn't matter which variable you call x and which you call y, as long as you are consistent).
To get a result that is easier to work with, we can convert the response to a data frame with appropriate column names:
new_data <- approx(scdt$od, scdt$conc, xout = unknowns) |>
setNames(c("od", "conc")) |>
as.data.frame()
new_data
#> od conc
#> 1 0.015 NA
#> 2 0.634 28.74532
#> 3 0.891 52.80899
#> 4 1.510 129.63918
#> 5 2.345 NA
#> 6 3.105 NA
Note that (as the manufacturer recommends), optical densities falling outside the extreme ranges of your calibration points will give NA values for concentration. To get these you would need to extrapolate rather than interpolate
Just to confirm this is what you're looking for, let's plot the results of this interpolation in red over the curve formed from the initial data:
plot(scdt$od, scdt$conc, type = "l", lty = 2)
points(scdt$od, scdt$conc)
points(new_data$od, new_data$conc, col = "red")
We can see that the estimated concentrations at each new optical density lie on the lines connecting the calibration points.
Setup:
I'm testing if the association between pairs of individuals for a trait (BMI) changes over time. I have repeated measures, where each individual in a pair gives BMI data at 7 points in time. Below is a simplified data frame in long format with Pair ID (the identifier given to each pair of individuals), BMI measurements for both individuals at each point in time (BMI_1 and BMI_2), and a time variable with seven intervals, coded as continuous.
Pair_ID
BMI_1
BMI_2
Time
1
25
22
1
1
23
24
2
1
22
31
3
1
20
27
4
1
30
26
5
1
31
21
6
1
19
18
7
2
21
17
1
2
22
27
2
2
24
22
3
2
25
20
4
First, I'm mainly interested in testing the within-pair association (the regression coefficient of BMI_2, below) and whether it changes over time (the interaction between BMI_2 and Time). I'd like to exclude any between-pair effects, so that I'm only testing associated over time within pairs.
I was planning on fitting a linear mixed model of the form:
lmer(BMI_1 ~ BMI_2 * Time + (BMI_2 | Pair_ID), Data)
I understand the parameters of the model (e.g., random slopes/intercepts), and that the BMI_2 * Time interaction tests whether the relationship between BMI_1 and BMI_2 is moderated by time.
However, I'm unsure how to identify the (mean) within-pair regression coefficients, and whether my approach is even suitable for this.
Second, I'm interested in understanding whether there is variation between pairs in the BMI_2 * Time interaction (i.e., the variance in slopes among pairs) - for example, does the associated between BMI_1 and BMI_2 increase over time in some pairs but not others?
For this, I was considering fitting a model like this:
lmer(BMI_1 ~ BMI_2 * Time + (BMI_2 : Time | Pair_ID), Data)
and then looking at the variance in the BMI_2 : Time random effect. As I understand it, large variance would imply that this interaction effect varied a lot between pairs.
Any help on these questions (especially the first question) would be greatly appreciated.
P.s., sorry if the question is poorly formatted. It's my first attempt.
Answering for completeness. #benimwolfspelz's comment is spot on. This is known as "contextual effects" in some areas of applied work. The idea is to split the variable into between and within components by mean-centering each group and fitting the mean-centred variable (which will estimate the within component) and the group means (which will estimate the between component).
Could someone help me to determine the correct random variable structure in my binomial GLMM in lme4?
I will first try to explain my data as best as I can. I have binomial data of seedlings that were eaten (1) or not eaten (0), together with data of vegetation cover. I try to figure out if there is a relationship between vegetation cover and the probability of a tree being eaten, as the other vegetation is a food source that could attract herbivores to a certain forest patch.
The data is collected in ~90 plots scattered over a National Park for 9 years now. Some were measured all years, some were measured only a few years (destroyed/newly added plots). The original datasets is split in 2 (deciduous vs coniferous), both containing ~55.000 entries. Per plot about 100 saplings were measured every time, so the two separate datasets probably contain about 50 trees per plot (though this will not always be the case, since the decid:conif ratio is not always equal). Each plot consists of 4 subplots.
I am aware that there might be spatial autocorrelation due to plot placement, but we will not correct for this, yet.
Every year the vegetation is surveyed in the same period. Vegetation cover is estimated at plot-level, individual trees (binary) are measured at a subplot-level.
All trees are measured, so the amount of responses per subplot will differ between subplots and years, as the forest naturally regenerates.
Unfortunately, I cannot share my original data, but I tried to create an example that captures the essentials:
#set seed for whole procedure
addTaskCallback(function(...) {set.seed(453);TRUE})
# Generate vector containing individual vegetation covers (in %)
cover1vec <- c(sample(0:100,10, replace = TRUE)) #the ',number' is amount of covers generated
# Create dataset
DT <- data.frame(
eaten = sample(c(0,1), 80, replace = TRUE),
plot = as.factor(rep(c(1:5), each = 16)),
subplot = as.factor(rep(c(1:4), each = 2)),
year = as.factor(rep(c(2012,2013), each = 8)),
cover1 = rep(cover1vec, each = 8)
)
Which will generate this dataset:
>DT
eaten plot subplot year cover1
1 0 1 1 2012 4
2 0 1 1 2012 4
3 1 1 2 2012 4
4 1 1 2 2012 4
5 0 1 3 2012 4
6 1 1 3 2012 4
7 0 1 4 2012 4
8 1 1 4 2012 4
9 1 1 1 2013 77
10 0 1 1 2013 77
11 0 1 2 2013 77
12 1 1 2 2013 77
13 1 1 3 2013 77
14 0 1 3 2013 77
15 1 1 4 2013 77
16 0 1 4 2013 77
17 0 2 1 2012 46
18 0 2 1 2012 46
19 0 2 2 2012 46
20 1 2 2 2012 46
....etc....
80 0 5 4 2013 82
Note1: to clarify again, in this example the number of responses is the same for every subplot:year combination, making the data balanced, which is not the case in the original dataset.
Note2: this example can not be run in a GLMM, as I get a singularity warning and all my random effect measurements are zero. Apparently my example is not appropriate to actually use (because using sample() caused the 0 and 1 to be in too even amounts to have large enough effects?).
As you can see from the example, cover data is the same for every plot:year combination.
Plots are measured multiple years (only 2012 and 2013 in the example), so there are repeated measures.
Additionally, a year effect is likely, given the fact that we have e.g. drier/wetter years.
First I thought about the following model structure:
library(lme4)
mod1 <- glmer(eaten ~ cover1 + (1 | year) + (1 | plot), data = DT, family = binomial)
summary(mod1)
Where (1 | year) should correct for differences between years and (1 | plot) should correct for the repeated measures.
But then I started thinking: all trees measured in plot 1, during year 2012 will be more similar to each other than when they are compared with (partially the same) trees from plot 1, during year 2013.
So, I doubt that this random model structure will correct for this within plot temporal effect.
So my best guess is to add another random variable, where this "interaction" is accounted for.
I know of two ways to possibly achieve this:
Method 1.
Adding the random variable " + (1 | year:plot)"
Method 2.
Adding the random variable " + (1 | year/plot)"
From what other people told me, I still do not know the difference between the two.
I saw that Method 2 added an extra random variable (year.1) compared to Method 1, but I do not know how to interpret that extra random variable.
As an example, I added the Random effects summary using Method 2 (zeros due to singularity issues with my example data):
Random effects:
Groups Name Variance Std.Dev.
plot.year (Intercept) 0 0
plot (Intercept) 0 0
year (Intercept) 0 0
year.1 (Intercept) 0 0
Number of obs: 80, groups: plot:year, 10; plot, 5; year, 2
Can someone explain me the actual difference between Method 1 and Method 2?
I am trying to understand what is happening, but cannot grasp it.
I already tried to get advice from a colleague and he mentioned that it is likely more appropriate to use cbind(success, failure) per plot:year combination.
Via this site I found that cbind is used in binomial models when Ntrails > 1, which I think is indeed the case given our sampling procedure.
I wonder, if cbind is already used on a plot:year combination, whether I need to add a plot:year random variable?
When using cbind, the example data would look like this:
>DT3
plot year cover1 Eaten_suc Eaten_fail
8 1 2012 4 4 4
16 1 2013 77 4 4
24 2 2012 46 2 6
32 2 2013 26 6 2
40 3 2012 91 2 6
48 3 2013 40 3 5
56 4 2012 61 5 3
64 4 2013 19 2 6
72 5 2012 19 5 3
80 5 2013 82 2 6
What would be the correct random model structure and why?
I was thinking about:
Possibility A
mod4 <- glmer(cbind(Eaten_suc, Eaten_fail) ~ cover1 + (1 | year) + (1 | plot),
data = DT3, family = binomial)
Possibility B
mod5 <- glmer(cbind(Eaten_suc, Eaten_fail) ~ cover1 + (1 | year) + (1 | plot) + (1 | year:plot),
data = DT3, family = binomial)
But doesn't cbind(success, failure) already correct for the year:plot dependence?
Possibility C
mod6 <- glmer(cbind(Eaten_suc, Eaten_fail) ~ cover1 + (1 | year) + (1 | plot) + (1 | year/plot),
data = DT3, family = binomial)
As I do not yet understand the difference between year:plot and year/plot
Thus: Is it indeed more appropriate to use the cbind-method than the raw binary data? And what random model structure would be necessary to prevent pseudoreplication and other dependencies?
Thank you in advance for your time and input!
EDIT 7/12/20: I added some extra information about the original data
You are asking quite a few questions in your question. I'll try to cover them all, but I do suggest reading the documentation and vignette from lme4 and the glmmFAQ page for more information. Also I'd highly recommend searching for these topics on google scholar, as they are fairly well covered.
I'll start somewhere simple
Note 2 (why is my model singular?)
Your model is highly singular, because the way you are simulating your data does not indicate any dependency between the data itself. If you wanted to simulate a binomial model you would use g(eta) = X %*% beta to simulate your linear predictor and thus the probability for success. One can then use this probability for simulating the your binary outcome. This would thus be a 2 step process, first using some known X or randomly simulated X given some prior distribution of our choosing. In the second step we would then use rbinom to simulate binary outcome while keeping it dependent on our predictor X.
In your example you are simulating independent X and a y where the probability is independent of X as well. Thus, when we look at the outcome y the probability of success is equal to p=c for all subgroup for some constant c.
Can someone explain me the actual difference between Method 1 and Method 2? ((1| year:plot) vs (1|year/plot))
This is explained in the package vignette fitting linear mixed effects models with lme4 in the table on page 7.
(1|year/plot) indicates that we have 2 mixed intercept effects, year and plot and plot is nested within year.
(1|year:plot) indicates a single mixed intercept effect, plot nested within year. Eg. we do not include the main effect of year. It would be somewhat similar to having a model without intercept (although less drastic, and interpretation is not destroyed).
It is more common to see the first rather than the second, but we could write the first as a function of the second (1|year) + (1|year:plot).
Thus: Is it indeed more appropriate to use the cbind-method than the raw binary data?
cbind in a formula is used for binomial data (or multivariate analysis), while for binary data we use the raw vector or 0/1 indicating success/failure, eg. aggregate binary data (similar to how we'd use glm). If you are uninterested in the random/fixed effect of subplot, you might be able to aggregate your data across plots, and then it would likely make sense. Otherwise stay with you 0/1 outcome vector indicating either success or failures.
What would be the correct random model structure and why?
This is a topic that is extremely hard to give a definitive answer to, and one that is still actively researched. Depending on your statistical paradigm opinions differ greatly.
Method 1: The classic approach
Classic mixed modelling is based upon knowledge of the data you are working with. In general there are several "rules of thumb" for choosing these parameters. I've gone through a few in my answer here. In general if you are "not interested" in the systematic effect and it can be thought of as a random sample of some population, then it could be a random effect. If it is the population, eg. samples do not change if the process is repeated, then it likely shouldn't.
This approach often yields "decent" choices for those who are new to mixed effect models, but is highly criticized by authors who tend towards methods similar to those we'd use in non-mixed models (eg. visualizing to base our choice and testing for significance).
Method 2: Using visualization
If you are able to split your data into independent subgroups and keeping the fixed effect structure a reasonable approach for checking potential random effects is the estimate marginal models (eg. using glm) across these subgroups and seeing if the fixed effects are "normally distributed" between these observations. The function lmList (in lme4) is designed for this specific approach. In linear models we would indeed expect these to be normally distributed, and thus we can get an indication whether a specific grouping "might" be a valid random effect structure. I believe the same is approximately true in the case of generalized linear models, but I lack references. I know that Ben Bolker have advocated for this approach in a prior article of his (the first reference below) that I used during my thesis. However this is only a valid approach for strictly separable data, and the implementation is not robust in the case where factor levels are not shared across all groups.
So in short: If you have the right data, this approach is simple, fast and seemingly highly reliable.
Method 3: Fitting maximal/minimal models and decreasing/expanding model based on AIC or AICc (or p-value tests or alternative metrics)
Finally an alternative to use a "step-wise"-like procedure. There are advocates of both starting with maximal and minimal models (I'm certain at least one of my references below talk about problems with both, otherwise check glmmFAQ) and then testing your random effects for their validity. Just like classic regression this is somewhat of a double-edged sword. The reason is both extremely simple to understand and amazingly complex to comprehend.
For this method to be successful you'd have to perform cross-validation or out-of-sample validation to avoid selection bias just like standard models, but unlike standard models sampling becomes complicated because:
The fixed effects are conditional on the random structure.
You will need your training and testing samples to be independent
As this is dependent on your random structure, and this is chosen in a step-wise approach it is hard to avoid information leakage in some of your models.
The only certain way to avoid problems here is to define the space
that you will be testing and selecting samples based on the most
restrictive model definition.
Next we also have problems with choice of metrics for evaluation. If one is interested in the random effects it makes sense to use AICc (AIC estimate of the conditional model) while for fixed effects it might make more sense to optimize AIC (AIC estimate of the marginal model). I'd suggest checking references to AIC and AICc on glmmFAQ, and be wary since the large-sample results for these may be uncertain outside a very reestrictive set of mixed models (namely "enough independent samples over random effects").
Another approach here is to use p-values instead of some metric for the procedure. But one should likely be even more wary of test on random effects. Even using a Bayesian approach or bootstrapping with incredibly high number of resamples sometimes these are just not very good. Again we need "enough independent samples over random effects" to ensure the accuracy.
The DHARMA provides some very interesting testing methods for mixed effects that might be better suited. While I was working in the area the author was still (seemingly) developing an article documenting the validity of their chosen method. Even if one does not use it for initial selection I can only recommend checking it out and deciding upon whether one believes in their methods. It is by far the most simple approach for a visual test with simple interpretation (eg. almost no prior knowledge is needed to interpret the plots).
A final note on this method would thus be: It is indeed an approach, but one I would personally not recommend. It requires either extreme care or the author accepting ignorance of model assumptions.
Conclusion
Mixed effect parameter selection is something that is difficult. My experience tells me that mostly a combination of method 1 and 2 are used, while method 3 seems to be used mostly by newer authors and these tend to ignore either out-of-sample error (measure model metrics based on the data used for training), ignore independence of samples problems when fitting random effects or restrict themselves to only using this method for testing fixed effect parameters. All 3 do however have some validity. I myself tend to be in the first group, and base my decision upon my "experience" within the field, rule-of-thumbs and the restrictions of my data.
Your specific problem.
Given your specific problem I would assume a mixed effect structure of (1|year/plot/subplot) would be the correct structure. If you add autoregressive (time-spatial) effects likely year disappears. The reason for this structure is that in geo-analysis and analysis of land plots the classic approach is to include an effect for each plot. If each plot can then further be indexed into subplot it is natural to think of "subplot" to be nested in "plot". Assuming you do not model autoregressive effects I would think of time as random for reasons that you already stated. Some years we'll have more dry and hotter weather than others. As the plots measured will have to be present in a given year, these would be nested in year.
This is what I'd call the maximal model and it might not be feasible depending on your amount of data. In this case I would try using (1|time) + (1|plot/subplot). If both are feasible I would compare these models, either using bootstrapping methods or approximate LRT tests.
Note: It seems not unlikely that (1|time/plot/subplot) would result in "individual level effects". Eg 1 random effect per row in your data. For reasons that I have long since forgotten (but once read) it is not plausible to have individual (also called subject-level) effects in binary mixed models. In this case It might also make sense to use the alternative approach or test whether your model assumptions are kept when withholding subplot from your random effects.
Below I've added some useful references, some of which are directly relevant to the question. In addition check out the glmmFAQ site by Ben Bolker and more.
References
Bolker, B. et al. (2009). „Generalized linear mixed models: a practical guide for ecology and evolution“. In: Trends in ecology & evolution 24.3, p. 127–135.
Bolker, B. et al. (2011). „GLMMs in action: gene-by-environment interaction in total fruit production of wild populations of Arabidopsis thaliana“. In: Revised version, part 1 1, p. 127–135.
Eager, C. og J. Roy (2017). „Mixed effects models are sometimes terrible“. In: arXiv preprint arXiv:1701.04858. url: https://arxiv.org/abs/1701.04858 (last seen 19.09.2019).
Feng, Cindy et al. (2017). „Randomized quantile residuals: an omnibus model diagnostic tool with unified reference distribution“. In: arXiv preprint arXiv:1708.08527. (last seen 19.09.2019).
Gelman, A. og Jennifer Hill (2007). Data Analysis Using Regression and Multilevel/Hierarchical Models. Cambridge University Press.
Hartig, F. (2019). DHARMa: Residual Diagnostics for Hierarchical (Multi-Level / Mixed) Regression Models. R package version 0.2.4. url: http://florianhartig.github.io/DHARMa/ (last seen 19.09.2019).
Lee, Y. og J. A. Nelder (2004). „Conditional and Marginal Models: Another View“. In: Statistical Science 19.2, p. 219–238.
doi: 10.1214/088342304000000305. url: https://doi.org/10.1214/088342304000000305
Lin, D. Y. et al. (2002). „Model-checking techniques based on cumulative residuals“. In: Biometrics 58.1, p. 1–12. (last seen 19.09.2019).
Lin, X. (1997). „Variance Component Testing in Generalised Linear Models with Random Effects“. In: Biometrika 84.2, p. 309–326. issn: 00063444. url: http://www.jstor.org/stable/2337459
(last seen 19.09.2019).
Stiratelli, R. et al. (1984). „Random-effects models for serial observations with binary response“. In:
Biometrics, p. 961–971.
I am constructing a GAMM model (for the first time) to compare longitudinal slopes of cognitive performance in a Bipolar Disorder (BD) sample, compared to a control (HC) sample. The study design is referred to as an "accelerated longitudinal study" where participants across a large span of ages 25-60, are followed for 2 years (HC group) and 4 years (BD group).
Hypothesis (1) The BD group’s yearly rate of change on processing speed will be higher overall than the healthy control group, suggesting a more rapid cognitive decline in BD than seen in HC.
Here is my R code formula, which I think is a bit off:
RUN2 <- gamm4(BACS_SC_R ~ group + s(VISITMONTH, bs = "cc") +
s(VISITMONTH, bs = "cc", by=group), random=~(1|SUBNUM), data=Df, REML = TRUE)
The visitmonth variable is coded as "months from first visit." Visit 1 would equal 0, and the following visits (3 per year) are coded as months elapsed from visit 1. Is a cyclic smooth correct in this case?
I plan on adding additional variables (i.e peripheral inflammation) to the model to predict individual slopes of cognitive trajectories in BD.
If you have any other suggestions, it would be greatly appreciated. Thank you!
If VISITMONTH is over years (i.e. for a BD observation we would have VISITMONTH in {0, 1, 2, ..., 48} (for the four years)), then no, you don't want a cyclic smooth unless there is some 4-year periodicity that would mean 0 and 11 should be constrained to be the same.
The default thin plate spline bs = 'tp' should suffice.
I'm also assuming that there are many possible values for VISITMONTH as not everyone was followed up at the same monthly intervals? Otherwise you're not going to have many degrees of freedom available for the temporal smooth.
Is group coded as an ordered factor here? If so that's great; the by smooth will encode the difference between the reference level (be sure to set HC as the reference level) and the other level so you can see directly in the summary a test for a difference of the BD group.
It's not clear how you are dealing with the fact that HC are followed up over fewer months than the BD group. It looks like the model has VISITMONTH representing the full time of the study not just a winthin-year term. So how do you intend to compare the BD group with the HC group for the 2 years where the HC group are not observed?
So help would be much appreciated!
I have already completed a CCA plot which shows 7 sites, about 15 species and 6 environmental variables. However, it is saying that the unconstrained axis is 0 and I cannot complete an ANOVA on my CCA results in order to see what the significance of the axes are. I also attempted to use the spenvcor function to see the environmental to species correlation and it is giving me 1's for all of the axes.
So I am definitely doing something wrong but I just can't figure out what.
Here is my code:
MayEnviro <- read.csv("MayEnviro.csv", header=TRUE)
MaySpecies <- read.csv("MaySpecies.csv", header=TRUE)
t <- cca(MaySpecies,
MayEnviro[, c("AFDM","Chla","Chloride","TSS","TN","TP","Velocity")])
spenvcor(t)
The number of axes you can derive from a data set with n = 7 sites, m = 15 species is min(n, m) - 1, which is 6. As you also have 6 constraints (the environmental variables) you explain the data exactly and there is no residual variance to work with. In fact there are no constraints on the solution and the result is just like CA.
In this instance, with so few sites, you should look to fit a model with fewer constraints, say 2 or 3 at most.