Commit f5ac0fe9 by Eric Coissac

Make a complete version of the anova function

parent a5ddbfd1
#' @title ProcMod
#' @description blabla
#' @author Christelle Gonindard-Melodelima
#'
require(matlib)
#' Compute the variance, covariance matrix of K coordinate matrix
#' Compute the variance, covariance matrix of K coordinate matrices
#'
#' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima
#' @author Eric Coissac & Christelle Gonindard-Melodelima
#' @export
mvar = function(...) {
......@@ -38,7 +42,7 @@ mvar = function(...) {
return(CovXXs)
}
#' Compute the correlation matrix of K coordinate matrix
#' Compute the correlation matrix of K coordinate matrices
#'
#' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima
......@@ -50,6 +54,8 @@ mcor = function(...) {
return(cov/vv)
}
#' Performs a procruste model on a set of coordinate matrices
#'
#' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima
#' @export
......@@ -133,14 +139,14 @@ pm = function (model,data) {
names(scales)=attr(terms,"term.labels")
results = list(coefficients = scales,
fitted.values=yhat,
residuals=Y - yhat,
call=cl,
model=vars,
# model=c(list(Y=YC),XCs),
terms = terms,
A = A_xys
results = list(coefficients = scales,
fitted.values = yhat,
residuals = Y - yhat,
df.residual = nrow(Y) - length(scales) - 2,
call = cl,
model = vars,
terms = terms,
A = A_xys
)
class(results)="pm"
......@@ -148,6 +154,8 @@ pm = function (model,data) {
return(results)
}
#' Default display function for `pm` objects.
#'
#' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima
#' @export
......@@ -158,6 +166,8 @@ print.pm = function(m,...) {
invisible(m)
}
#' Default plot function for `pm` objects.
#'
#' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima
#' @export
......@@ -203,12 +213,16 @@ plot.pm = function(m,
pos=3)
anova = anova(m)
v=c(anova$SCX,
interaction=anova$SCI,
error=anova$SCE)
v=anova[,"Sum Sq"]
names(v)=rownames(anova)
barplot(v/sum(v),las=2)
}
#' Anova function for `pm` objects.
#'
#' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima
#' @export
anova.pm = function(m,...) {
ctrace <- function(MAT) sum(MAT^2)
......@@ -239,9 +253,29 @@ anova.pm = function(m,...) {
SCE = sum(m$residuals^2)
SCI = VarY - SCE - sum(SChat)
return(list(SCI=SCI,
SCX=VarYhats,
SCE=SCE))
SumSq = c(VarYhats,Interactions=SCI,Residuals=SCE)
Df = c(rep(1,length(VarYhats)+1),m$df.residual)
MeanSq = SumSq/Df
Fvalue = c(MeanSq[-length(MeanSq)]/MeanSq[length(MeanSq)],NA)
Pvalue = 1-pf(Fvalue,
Df[-length(MeanSq)],
Df[length(MeanSq)])
result = data.frame(Df,
SumSq,
MeanSq,
Fvalue,
Pvalue)
colnames(result)=c("Df","Sum Sq","Mean Sq","F value","Pr(>F)")
attr(result, "heading")= paste("Analysis of Variance Table\n\nResponse:",
all.vars(m$terms)[1]
)
class(result)=c("anova",class(result))
return(result)
}
mprocuste = function (Y, ...)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment