Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
legTools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
leg
legTools
Commits
bc2671c6
Commit
bc2671c6
authored
9 years ago
by
Walmes Zeviani
Browse files
Options
Downloads
Patches
Plain Diff
Add panel.segplot.by, an improved version of the function in the wzRfun package.
parent
a4afb583
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
R/panel.segplot.by.R
+85
-0
85 additions, 0 deletions
R/panel.segplot.by.R
with
85 additions
and
0 deletions
R/panel.segplot.by.R
0 → 100644
+
85
−
0
View file @
bc2671c6
#' @title Lattice panel to non overlapping segments in \code{segplot()}
#'
#' @name panel.segplot.by
#'
#' @description This panel allows no overlapping of segments in
#' \code{latticeExtra::segplot()} when using the argument groups.
#'
#' @param x,y,z,data,centers,subscripts,... see
#' \code{\link[latticeExtra]{segplot}}.
#' @param groups the grouping variable. Must be a factor.
#' @param f numeric, factor that is the vertical distance among
#' arrows. In general a value less than 1. Default is 0.05.
#' @param rev logical, use the reverse order of the factor levels to
#' place the segments. Default is \code{FALSE}.
#'
#' @return None is returned.
#'
#' @seealso \code{\link[latticeExtra]{segplot}}
#'
#' @author Walmes Zeviani, \email{walmes@@ufpr.br}
#'
#' @export
#'
#' @examples
#'
#' library(latticeExtra)
#'
#' m0 <- lm(log(breaks)~wool*tension, data=warpbreaks)
#' anova(m0)
#' par(mfrow=c(2,2)); plot(m0); layout(1)
#'
#' pred <- data.frame(wool=c("A", "B", "A", "B", "A", "B"),
#' tension=c("L", "L", "M", "M", "H", "H"))
#'
#' X <- matrix(c(1, 1, 1, 1, 1, 1,
#' 0, 1, 0, 1, 0, 1,
#' 0, 0, 1, 1, 0, 0,
#' 0, 0, 0, 0, 1, 1,
#' 0, 0, 0, 1, 0, 0,
#' 0, 0, 0, 0, 0, 1), nrow=6, ncol=6)
#'
#' ## Estimate and standart error.
#' ## X%*%coef(m0)
#' ## sqrt(diag(X%*%vcov(m0)%*%t(X)))
#'
#' U <- chol(vcov(m0))
#' pred$est <- X%*%coef(m0)
#' pred$se <- sqrt(apply(X%*%t(U), MARGIN=1, FUN=function(x) sum(x^2)))
#'
#' tval <- qt(p=c(lwr=0.025, upr=0.975), df=df.residual(m0))
#' pred <- cbind(pred, sweep(x=outer(pred$se, tval, "*"),
#' MARGIN=1, STATS=pred$est, FUN="+"))
#'
#' ## Overlapping segments.
#' segplot(wool~lwr+upr, centers=est, data=pred, draw=FALSE)
#'
#' ## Prefer ordering always before using "pch=".
#' pred <- pred[with(pred, order(tension, wool)), ]
#'
#' segplot(tension~lwr+upr, data=pred,
#' centers=est, draw=FALSE,
#' ylab="Tension level",
#' xlab=expression("Estimate"%+-%"error margin for a 0.95 CI"),
#' groups=wool, f=0.05, rev=TRUE,
#' pch=as.integer(pred$wool),
#' panel=panel.segplot.by,
#' key=list(title="Type of wool", cex.title=1.1,
#' text=list(levels(pred$wool)),
#' lines=list(pch=1:2, lty=1),
#' divide=1, type="o"))
#'
panel.segplot.by
<-
function
(
x
,
y
,
z
,
data
,
centers
,
subscripts
,
groups
,
f
=
0.05
,
rev
=
FALSE
,
...
){
if
(
!
missing
(
data
)){
da
<-
eval
(
data
,
envir
=
parent.frame
())
groups
<-
da
[,
deparse
(
substitute
(
groups
))]
}
d
<-
2
*
((
as.numeric
(
groups
)
-1
)
/
(
nlevels
(
groups
)
-1
))
-1
if
(
rev
){
d
<-
rev
(
d
)
}
z
<-
as.numeric
(
z
)
+
f
*
d
panel.segplot
(
x
,
y
,
z
,
centers
=
centers
,
subscripts
=
subscripts
,
...
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment