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
Harbor Registry
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
411aa7cb
Commit
411aa7cb
authored
9 years ago
by
Walmes Zeviani
Browse files
Options
Downloads
Patches
Plain Diff
Add function poly.gui(), a gWidgets function to teach polynomial regression.
parent
ca108e72
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
DESCRIPTION
+2
-2
2 additions, 2 deletions
DESCRIPTION
NAMESPACE
+1
-0
1 addition, 0 deletions
NAMESPACE
R/poly.gui.R
+134
-0
134 additions, 0 deletions
R/poly.gui.R
man/poly.gui.Rd
+37
-0
37 additions, 0 deletions
man/poly.gui.Rd
with
174 additions
and
2 deletions
DESCRIPTION
+
2
−
2
View file @
411aa7cb
...
@@ -15,8 +15,8 @@ Imports:
...
@@ -15,8 +15,8 @@ Imports:
latticeExtra
latticeExtra
Suggests:
Suggests:
plyr,
plyr,
rpanel
,
gWidgets
,
gWidgets
gWidgets
tcltk
License: GPL-3 | file LICENSE
License: GPL-3 | file LICENSE
URL: http://git.leg.ufpr.br/leg/legTools
URL: http://git.leg.ufpr.br/leg/legTools
BugReports: http://git.leg.ufpr.br/leg/legTools/issues
BugReports: http://git.leg.ufpr.br/leg/legTools/issues
...
...
This diff is collapsed.
Click to expand it.
NAMESPACE
+
1
−
0
View file @
411aa7cb
# Generated by roxygen2 (4.1.1): do not edit by hand
# Generated by roxygen2 (4.1.1): do not edit by hand
export(poly.gui)
export(subsetDropAll)
export(subsetDropAll)
This diff is collapsed.
Click to expand it.
R/poly.gui.R
0 → 100644
+
134
−
0
View file @
411aa7cb
#' @title Polynomial regression GUI
#'
#' @name poly.gui
#'
#' @description This function opens a interface to control the
#' polynomial degree in linear regression. It shows the observed values
#' and the corresponding fitted curve superimposed with confidence bands
#' (for the fitted value) and show the residuals plot too. It assumes
#' that \code{gWidgets} and \code{gWidgetstcltk} packages are available.
#'
#' @param x,y independent and dependent (numeric) regression variables.
#'
#' @param data an optional \code{data.frame}.
#'
#' @param er stands for extend range. It is used to extend the plotting
#' range by a fraction on both sides and directions. Default is
#' 0.05. See \link[grDevices]{extendrange}.
#'
#' @return None is returned by the function.
#'
#' @export
#' @examples
#' \donttest{
#'
#' poly.gui(x=area, y=peri, data=rock, er=0.3)
#' poly.gui(x=speed, y=dist, data=cars, er=0.3)
#' poly.gui(x=eruptions, y=waiting, data=faithful, er=0.3)
#'
#' }
poly.gui
<-
function
(
x
,
y
,
data
,
er
=
0.05
){
##
##-------------------------------------------
## Loading the required packages.
##
if
(
!
requireNamespace
(
"gWidgets"
,
quietly
=
TRUE
)){
stop
(
"`gWidgets` needed for this function to work. Please install it."
,
call.
=
FALSE
)
}
if
(
!
requireNamespace
(
"gWidgetstcltk"
,
quietly
=
TRUE
)){
stop
(
"`gWidgetstcltk` needed for this function to work. Please install it."
,
call.
=
FALSE
)
}
stopifnot
(
require
(
gWidgets
))
stopifnot
(
require
(
gWidgetstcltk
))
options
(
guiToolkit
=
"tcltk"
)
##
##-------------------------------------------
## Functions to annotate in the plot upper margin.
##
annotations
<-
function
(
lm.obj
){
mtext
(
side
=
3
,
adj
=
0
,
line
=
1.5
,
text
=
sprintf
(
"X rank: %i"
,
lm.obj
$
rank
))
mtext
(
side
=
3
,
adj
=
0
,
line
=
0.5
,
text
=
sprintf
(
"Residual DF: %i"
,
lm.obj
$
df.residual
))
press
<-
sum
((
residuals
(
lm.obj
)
/
(
1
-
hatvalues
(
lm.obj
)))
^
2
)
mtext
(
side
=
3
,
adj
=
1
,
line
=
0.5
,
text
=
sprintf
(
"PRESS: %0.2f"
,
press
))
sm
<-
summary
(
lm.obj
)
lastcoef
<-
sprintf
(
"High term p-value: %0.5f"
,
sm
$
coeff
[
length
(
coef
(
lm.obj
)),
4
])
mtext
(
side
=
3
,
adj
=
1
,
line
=
2.5
,
text
=
lastcoef
)
mtext
(
side
=
3
,
adj
=
1
,
line
=
1.5
,
text
=
sprintf
(
"R² (adj. R²): %0.2f (%0.2f)"
,
100
*
sm
$
r.squared
,
100
*
sm
$
adj.r.squared
))
}
##
##-------------------------------------------
## Auxiliary variables not controled by the GUI.
##
xlab
<-
deparse
(
substitute
(
x
))
ylab
<-
deparse
(
substitute
(
y
))
if
(
!
missing
(
data
)){
da
<-
eval
(
data
,
envir
=
parent.frame
())
x
<-
da
[,
deparse
(
substitute
(
x
))]
y
<-
da
[,
deparse
(
substitute
(
y
))]
}
maxd
<-
as.integer
(
length
(
unique
(
x
))
-1
)
xr
<-
extendrange
(
x
,
f
=
er
)
yr
<-
extendrange
(
y
,
f
=
er
)
newdata
<-
data.frame
(
x
=
seq
(
xr
[
1
],
xr
[
2
],
length.out
=
200
))
##
##-------------------------------------------
## Function controled by the GUI.
##
draw.poly
<-
function
(
h
,
...
){
svalue
(
degree
)
<-
min
(
c
(
max
(
c
(
1L
,
svalue
(
degree
)
+
h
$
action
$
val
)),
maxd
))
m0
<-
lm
(
y
~
poly
(
x
,
degree
=
svalue
(
degree
)))
switch
(
svalue
(
plottype
),
"Scatter plot"
=
{
cb
<-
predict
(
m0
,
newdata
=
newdata
,
interval
=
"confidence"
)
plot
(
y
~
x
,
xlim
=
xr
,
ylim
=
yr
,
xlab
=
xlab
,
ylab
=
ylab
)
matlines
(
newdata
$
x
,
cb
,
lty
=
c
(
1
,
2
,
2
),
col
=
1
)
annotations
(
m0
)
},
"Residuals"
=
{
par
(
mfrow
=
c
(
2
,
2
))
plot
(
m0
)
layout
(
1
)
})
}
##
##-------------------------------------------
## Building the GUI.
##
w
<-
gwindow
(
title
=
"Polynomial regression"
,
visible
=
FALSE
)
g
<-
ggroup
(
container
=
w
,
horizontal
=
FALSE
)
gg_label
<-
ggroup
(
container
=
g
)
dlabel
<-
glabel
(
text
=
"Polynomial degree:"
,
container
=
gg_label
)
degree
<-
gedit
(
text
=
1
,
width
=
2
,
coerce.with
=
as.integer
,
handler
=
draw.poly
,
action
=
list
(
val
=
0L
),
container
=
gg_label
)
gg_buttons
<-
ggroup
(
container
=
g
)
gminus
<-
gbutton
(
text
=
"-"
,
handler
=
draw.poly
,
action
=
list
(
val
=
-1L
),
container
=
gg_buttons
)
gplus
<-
gbutton
(
text
=
"+"
,
handler
=
draw.poly
,
action
=
list
(
val
=
1L
),
container
=
gg_buttons
)
gg_radio
<-
ggroup
(
container
=
g
)
plottype
<-
gradio
(
items
=
c
(
"Scatter plot"
,
"Residuals"
),
horizontal
=
TRUE
,
handler
=
draw.poly
,
action
=
list
(
val
=
0L
),
container
=
gg_radio
)
do.call
(
what
=
draw.poly
,
args
=
list
(
h
=
list
(
degree
=
1L
)))
visible
(
w
)
<-
TRUE
invisible
()
}
This diff is collapsed.
Click to expand it.
man/poly.gui.Rd
0 → 100644
+
37
−
0
View file @
411aa7cb
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/poly.gui.R
\name{poly.gui}
\alias{poly.gui}
\title{Polynomial regression GUI}
\usage{
poly.gui(x, y, data, er = 0.05)
}
\arguments{
\item{x,y}{independent and dependent (numeric) regression variables.}
\item{data}{an optional \code{data.frame}.}
\item{er}{stands for extend range. It is used to extend the plotting
range by a fraction on both sides and directions. Default is
0.05. See \link[grDevices]{extendrange}.}
}
\value{
None is returned by the function.
}
\description{
This function opens a interface to control the
polynomial degree in linear regression. It shows the observed values
and the corresponding fitted curve superimposed with confidence bands
(for the fitted value) and show the residuals plot too. It assumes
that \code{gWidgets} and \code{gWidgetstcltk} packages are available.
}
\examples{
\donttest{
poly.gui(x=area, y=peri, data=rock, er=0.3)
poly.gui(x=speed, y=dist, data=cars, er=0.3)
poly.gui(x=eruptions, y=waiting, data=faithful, er=0.3)
}
}
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