Title: | Draw Three Dimensional Predict Plot Using Package 'rgl' |
---|---|
Description: | Draw 2 dimensional and three dimensional plot for multiple regression models using package 'ggplot2' and 'rgl'. Supports linear models (lm), generalized linear models (glm) and local polynomial regression fittings (loess). |
Authors: | Keon-Woong Moon [aut, cre] |
Maintainer: | Keon-Woong Moon <[email protected]> |
License: | GPL-2 |
Version: | 0.1.5 |
Built: | 2025-01-30 02:51:58 UTC |
Source: | https://github.com/cardiomoon/predict3d |
Add lines with labels to pre-existing ggplot
add_lines( p, df, xpos = 0.3, add.coord.fixed = TRUE, lty = NULL, color = NULL, size = 0.5, add_theme_bw2 = TRUE, ... )
add_lines( p, df, xpos = 0.3, add.coord.fixed = TRUE, lty = NULL, color = NULL, size = 0.5, add_theme_bw2 = TRUE, ... )
p |
An object of class ggplot |
df |
A data.frame. Required columns are slope, intercept and label |
xpos |
A numeric. Relative horizontal position |
add.coord.fixed |
Logical. Whether or not add coord_fixed() function |
lty |
line type |
color |
line color |
size |
line size |
add_theme_bw2 |
logical Whether or not add theme_bw2() |
... |
Further arguments to be passed to geom_text |
require(ggplot2) fit=lm(mpg~wt*hp,data=mtcars) df=calEquation(fit) p=ggplot(data=mtcars,aes(x=wt,y=mpg)) add_lines(p,df) add_lines(p,df,lty=1:3,color=1:3,size=1) fit=lm(mpg~wt*vs,data=mtcars) df=calEquation(fit) p=ggplot(data=mtcars)+geom_point(aes(x=wt,y=mpg)) add_lines(p,df) add_lines(p,df,lty=1:2,color=1:2,size=1)+theme_bw()
require(ggplot2) fit=lm(mpg~wt*hp,data=mtcars) df=calEquation(fit) p=ggplot(data=mtcars,aes(x=wt,y=mpg)) add_lines(p,df) add_lines(p,df,lty=1:3,color=1:3,size=1) fit=lm(mpg~wt*vs,data=mtcars) df=calEquation(fit) p=ggplot(data=mtcars)+geom_point(aes(x=wt,y=mpg)) add_lines(p,df) add_lines(p,df,lty=1:2,color=1:2,size=1)+theme_bw()
Whether a string vector can be converted to numeric
beNumeric(x)
beNumeric(x)
x |
A string vector |
x=c("age","22.5","11/2") beNumeric(x)
x=c("age","22.5","11/2") beNumeric(x)
calculated slope and intercept from object of class lm
calEquation( fit, mode = 1, pred = NULL, modx = NULL, modx.values = NULL, label = NULL, maxylev = 6, digits = 2 )
calEquation( fit, mode = 1, pred = NULL, modx = NULL, modx.values = NULL, label = NULL, maxylev = 6, digits = 2 )
fit |
An object of class lm |
mode |
A numeric |
pred |
name of predictor variable |
modx |
name of modifier variable |
modx.values |
Numeric. Values of modifier variable |
label |
A character string |
maxylev |
maximum length of unique value of variable to be treated as a categorial variable |
digits |
Integer indicating the number of decimal places |
fit=lm(mpg~wt*hp+carb,data=mtcars) calEquation(fit) calEquation(fit,pred="hp")
fit=lm(mpg~wt*hp+carb,data=mtcars) calEquation(fit) calEquation(fit,pred="hp")
expand.grid with two data.frames
expand.grid2(df1, df2)
expand.grid2(df1, df2)
df1 |
A data.frame |
df2 |
A data.frame |
Make a new data set for prediction
fit2newdata( fit, predictors, mode = 1, pred.values = NULL, modx.values = NULL, mod2.values = NULL, colorn = 3, maxylev = 6, summarymode = 1 )
fit2newdata( fit, predictors, mode = 1, pred.values = NULL, modx.values = NULL, mod2.values = NULL, colorn = 3, maxylev = 6, summarymode = 1 )
fit |
An object of class "lm", "glm" or "loess" |
predictors |
Names of predictor variables in string |
mode |
A numeric. Useful when the variables are numeric. If 1, c(-1,0,1)*sd + mean is used. If 2, the 16th, 50th, 84th percentile values used. If 3 sequence over a the range of a vector used |
pred.values |
For which values of the predictors should be used? Default is NULL. If NULL, 20 seq_range is used. |
modx.values |
For which values of the moderator should lines be plotted? Default is NULL. If NULL, then the customary +/- 1 standard deviation from the mean as well as the mean itself are used for continuous moderators. If the moderator is a factor variable and modx.values is NULL, each level of the factor is included. |
mod2.values |
For which values of the second moderator should lines be plotted? Default is NULL. If NULL, then the customary +/- 1 standard deviation from the mean as well as the mean itself are used for continuous moderators. If the moderator is a factor variable and modx.values is NULL, each level of the factor is included. |
colorn |
The number of regression lines when the modifier variable(s) are numeric. |
maxylev |
An integer indicating the maximum number of levels of numeric variable be treated as a categorical variable |
summarymode |
An integer indicating method of extracting typical value of variables. If 1, typical() is used.If 2, mean() is used. |
fit=lm(mpg~hp*wt*cyl+carb+am,data=mtcars) fit2newdata(fit,predictors=c("hp","wt","am")) fit2newdata(fit,predictors=c("hp","wt","cyl")) fit2newdata(fit,predictors=c("hp")) fit2newdata(fit,predictors=c("hp","wt")) fit=loess(mpg~hp*wt*am,data=mtcars) fit2newdata(fit,predictors=c("hp")) ## Not run: mtcars$engine=ifelse(mtcars$vs==0,"V-shaped","straight") fit=lm(mpg~wt*engine,data=mtcars) fit2newdata(fit,predictors=c("wt","engine")) fit=lm(mpg~wt*factor(vs),data=mtcars) fit2newdata(fit,predictors=c("wt","vs")) fit2newdata(lm(mpg~hp*wt,data=mtcars),predictors=c("hp","wt"),mode=3,colorn=30) fit=lm(mpg~hp*log(wt),data=mtcars) fit2newdata(fit,predictors=c("hp","log(wt)")) fit=lm(mpg~hp*wt*factor(vs),data=mtcars) fit2newdata(fit,predictors=c("hp")) ## End(Not run) require(moonBook) fit=lm(log(NTAV)~I(age^2)*sex,data=radial) fit2newdata(fit,predictors=c("I(age^2)","sex"))
fit=lm(mpg~hp*wt*cyl+carb+am,data=mtcars) fit2newdata(fit,predictors=c("hp","wt","am")) fit2newdata(fit,predictors=c("hp","wt","cyl")) fit2newdata(fit,predictors=c("hp")) fit2newdata(fit,predictors=c("hp","wt")) fit=loess(mpg~hp*wt*am,data=mtcars) fit2newdata(fit,predictors=c("hp")) ## Not run: mtcars$engine=ifelse(mtcars$vs==0,"V-shaped","straight") fit=lm(mpg~wt*engine,data=mtcars) fit2newdata(fit,predictors=c("wt","engine")) fit=lm(mpg~wt*factor(vs),data=mtcars) fit2newdata(fit,predictors=c("wt","vs")) fit2newdata(lm(mpg~hp*wt,data=mtcars),predictors=c("hp","wt"),mode=3,colorn=30) fit=lm(mpg~hp*log(wt),data=mtcars) fit2newdata(fit,predictors=c("hp","log(wt)")) fit=lm(mpg~hp*wt*factor(vs),data=mtcars) fit2newdata(fit,predictors=c("hp")) ## End(Not run) require(moonBook) fit=lm(log(NTAV)~I(age^2)*sex,data=radial) fit2newdata(fit,predictors=c("I(age^2)","sex"))
Get aspect information of a ggplot
getAspectRatio(p)
getAspectRatio(p)
p |
A ggplot object |
calculate mean values of two consecutive number
getMeans(x)
getMeans(x)
x |
A numeric vector |
x=c(50,60,70) getMeans(x)
x=c(50,60,70) getMeans(x)
Make new formula
getNewFormula(fit, predictors = NULL)
getNewFormula(fit, predictors = NULL)
fit |
An object of class lm or glm |
predictors |
Names of variables to exclude |
fit=lm(mpg~factor(cyl)*factor(am)+wt+carb,data=mtcars) getNewFormula(fit,predictors=c("cyl","wt")) fit=lm(Sepal.Length~Sepal.Width*Petal.Length+Species,data=iris) getNewFormula(fit,predictors=c("Petal.Length")) fit=lm(mpg~hp*wt*factor(cyl),data=mtcars) getNewFormula(fit,predictors=c("hp","cyl")) fit=loess(mpg~hp*wt,data=mtcars) getNewFormula(fit,predictors=c("hp","wt"))
fit=lm(mpg~factor(cyl)*factor(am)+wt+carb,data=mtcars) getNewFormula(fit,predictors=c("cyl","wt")) fit=lm(Sepal.Length~Sepal.Width*Petal.Length+Species,data=iris) getNewFormula(fit,predictors=c("Petal.Length")) fit=lm(mpg~hp*wt*factor(cyl),data=mtcars) getNewFormula(fit,predictors=c("hp","cyl")) fit=loess(mpg~hp*wt,data=mtcars) getNewFormula(fit,predictors=c("hp","wt"))
Pick default color
gg_color_hue(n)
gg_color_hue(n)
n |
An integer |
Visualize predictions from the multiple regression models.
ggPredict( fit, pred = NULL, modx = NULL, mod2 = NULL, modx.values = NULL, mod2.values = NULL, dep = NULL, mode = 1, colorn = 3, maxylev = 6, show.point = getOption("ggPredict.show.point", TRUE), show.error = FALSE, error.color = "red", jitter = NULL, se = FALSE, alpha = 0.1, show.text = TRUE, add.modx.values = TRUE, add.loess = FALSE, labels = NULL, angle = NULL, xpos = NULL, vjust = NULL, digits = 2, facet.modx = FALSE, facetbycol = TRUE, plot = TRUE, summarymode = 1, ... )
ggPredict( fit, pred = NULL, modx = NULL, mod2 = NULL, modx.values = NULL, mod2.values = NULL, dep = NULL, mode = 1, colorn = 3, maxylev = 6, show.point = getOption("ggPredict.show.point", TRUE), show.error = FALSE, error.color = "red", jitter = NULL, se = FALSE, alpha = 0.1, show.text = TRUE, add.modx.values = TRUE, add.loess = FALSE, labels = NULL, angle = NULL, xpos = NULL, vjust = NULL, digits = 2, facet.modx = FALSE, facetbycol = TRUE, plot = TRUE, summarymode = 1, ... )
fit |
An object of class "lm" or "glm" |
pred |
The name of predictor variable |
modx |
Optional. The name of moderator variable |
mod2 |
Optional. The name of second moderator variable |
modx.values |
For which values of the moderator should lines be plotted? Default is NULL. If NULL, then the customary +/- 1 standard deviation from the mean as well as the mean itself are used for continuous moderators. If the moderator is a factor variable and modx.values is NULL, each level of the factor is included. |
mod2.values |
For which values of the second moderator should lines be plotted? Default is NULL. If NULL, then the customary +/- 1 standard deviation from the mean as well as the mean itself are used for continuous moderators. If the moderator is a factor variable and modx.values is NULL, each level of the factor is included. |
dep |
Optional. The name of dependent variable |
mode |
A numeric. Useful when the variables are numeric. If 1, c(-1,0,1)*sd + mean is used. If 2, the 14th, 50th, 86th percentile values used. If 3 sequence over a the range of a vector used |
colorn |
The number of regression lines when the modifier variable(s) are numeric. |
maxylev |
An integer indicating the maximum number of levels of numeric variable be treated as a categorical variable |
show.point |
Logical. Whether or not add points |
show.error |
Logical. Whether or not show error |
error.color |
color of error. dafault value is "red" |
jitter |
logical Whether or not use geom_jitter |
se |
Logical. Whether or not add confidence interval |
alpha |
A numeric. Transparency |
show.text |
Logical. Whether or not add regression equation as label |
add.modx.values |
Logical. Whether or not add moderator values to regression equation |
add.loess |
Logical. Whether or not add loess line |
labels |
labels on regression lines |
angle |
angle of text |
xpos |
x axis position of label |
vjust |
vertical alignment of labels |
digits |
integer indicating the number of decimal places |
facet.modx |
Create separate panels for each level of the moderator? Default is FALSE |
facetbycol |
Logical. |
plot |
Logical. Should a plot of the results be printed? Default is TRUE. |
summarymode |
An integer indicating method of extracting typical value of variables. If 1, typical() is used.If 2, mean() is used. |
... |
additional arguments to be passed to geom_text |
fit=loess(mpg~hp*wt*am,data=mtcars) ggPredict(fit) ggPredict(fit,hp) ## Not run: ggPredict(fit,hp,wt) fit=lm(mpg~wt*hp-1,data=mtcars) ggPredict(fit,xpos=0.7) fit=lm(mpg~hp*wt,data=mtcars) ggPredict(fit) ggPredict(fit,labels=paste0("label",1:3),xpos=c(0.3,0.6,0.4)) ggPredict(fit,se=TRUE) ggPredict(fit,mode=3,colorn=40,show.text=FALSE) fit=lm(log(mpg)~hp*wt,data=mtcars) ggPredict(fit,dep=mpg) fit=lm(mpg~hp*wt*cyl,data=mtcars) ggPredict(fit,modx=wt,modx.values=c(2,3,4,5),mod2=cyl,show.text=FALSE) ggPredict(fit,hp,wt,show.point=FALSE,se=TRUE,xpos=0.5) ggPredict(fit,modx=wt,xpos=0.3) ggPredict(fit) mtcars$engine=ifelse(mtcars$vs==0,"V-shaped","straight") fit=lm(mpg~wt*engine,data=mtcars) ggPredict(fit) require(TH.data) fit=glm(cens~pnodes*horTh,data=GBSG2,family=binomial) ggPredict(fit,pnodes,horTh,se=TRUE,xpos=c(0.6,0.3),angle=c(40,60),vjust=c(2,-0.5)) fit1=glm(cens~pnodes,data=GBSG2,family=binomial) ggPredict(fit1,vjust=1.5,angle=45) fit3=glm(cens~pnodes*age,data=GBSG2,family=binomial) ggPredict(fit3,pred=pnodes,modx=age,mode=3,colorn=10,show.text=FALSE) fit2=glm(cens~pnodes*age*horTh,data=GBSG2,family=binomial) ggPredict(fit2,pred=pnodes,modx=age,mod2=horTh,mode=3,colorn=10,show.text=FALSE) fit=lm(mpg~log(hp)*wt,data=mtcars) ggPredict(fit,hp,wt) fit=lm(mpg~hp*wt+disp+gear+carb+am,data=mtcars) ggPredict(fit,disp,gear,am) library(moonBook) fit=lm(weight~I(height^3)+I(height^2)+height+sex,data=radial) ggPredict(fit) predict3d(fit) ## End(Not run)
fit=loess(mpg~hp*wt*am,data=mtcars) ggPredict(fit) ggPredict(fit,hp) ## Not run: ggPredict(fit,hp,wt) fit=lm(mpg~wt*hp-1,data=mtcars) ggPredict(fit,xpos=0.7) fit=lm(mpg~hp*wt,data=mtcars) ggPredict(fit) ggPredict(fit,labels=paste0("label",1:3),xpos=c(0.3,0.6,0.4)) ggPredict(fit,se=TRUE) ggPredict(fit,mode=3,colorn=40,show.text=FALSE) fit=lm(log(mpg)~hp*wt,data=mtcars) ggPredict(fit,dep=mpg) fit=lm(mpg~hp*wt*cyl,data=mtcars) ggPredict(fit,modx=wt,modx.values=c(2,3,4,5),mod2=cyl,show.text=FALSE) ggPredict(fit,hp,wt,show.point=FALSE,se=TRUE,xpos=0.5) ggPredict(fit,modx=wt,xpos=0.3) ggPredict(fit) mtcars$engine=ifelse(mtcars$vs==0,"V-shaped","straight") fit=lm(mpg~wt*engine,data=mtcars) ggPredict(fit) require(TH.data) fit=glm(cens~pnodes*horTh,data=GBSG2,family=binomial) ggPredict(fit,pnodes,horTh,se=TRUE,xpos=c(0.6,0.3),angle=c(40,60),vjust=c(2,-0.5)) fit1=glm(cens~pnodes,data=GBSG2,family=binomial) ggPredict(fit1,vjust=1.5,angle=45) fit3=glm(cens~pnodes*age,data=GBSG2,family=binomial) ggPredict(fit3,pred=pnodes,modx=age,mode=3,colorn=10,show.text=FALSE) fit2=glm(cens~pnodes*age*horTh,data=GBSG2,family=binomial) ggPredict(fit2,pred=pnodes,modx=age,mod2=horTh,mode=3,colorn=10,show.text=FALSE) fit=lm(mpg~log(hp)*wt,data=mtcars) ggPredict(fit,hp,wt) fit=lm(mpg~hp*wt+disp+gear+carb+am,data=mtcars) ggPredict(fit,disp,gear,am) library(moonBook) fit=lm(weight~I(height^3)+I(height^2)+height+sex,data=radial) ggPredict(fit) predict3d(fit) ## End(Not run)
Decide whether a vector can be treated as a numeric variable
is.mynumeric(x, maxylev = 6)
is.mynumeric(x, maxylev = 6)
x |
A vector |
maxylev |
An integer indicating the maximum number of levels of numeric variable be treated as a categorical variable |
Generate regular sequences of desired length between minimum and maximal values
myseq(x, length = 20)
myseq(x, length = 20)
x |
a numeric vector |
length |
desired length of the sequence |
Convert a numeric vector into groups
number2group( x, mode = 1, values = NULL, silent = FALSE, label = "label", digits = 2, colorn = 3 )
number2group( x, mode = 1, values = NULL, silent = FALSE, label = "label", digits = 2, colorn = 3 )
x |
A numeric vector |
mode |
A numeric. If 1, mean(x) +c(-1,0,1)*sd(x) are used. If 2, quantile(x,probs=c(0.14,0.5,0.86),type=6) are used. If 3, values are used |
values |
A numeric vector |
silent |
A logical. Whether table of result will be shown |
label |
A character string |
digits |
integer indicating the number of decimal places |
colorn |
The number of regression lines when the modifier variable(s) are numeric |
number2group(iris$Sepal.Length,label="Sepal.Length") x=number2group(mtcars$wt,label="wt") x
number2group(iris$Sepal.Length,label="Sepal.Length") x=number2group(mtcars$wt,label="wt") x
Draw 3d predict plot using package 'rgl'
predict3d( fit, pred = NULL, modx = NULL, mod2 = NULL, dep = NULL, xlab = NULL, ylab = NULL, zlab = NULL, width = 640, colorn = 20, maxylev = 6, se = FALSE, show.summary = FALSE, overlay = NULL, show.error = FALSE, show.legend = FALSE, bg = NULL, type = "s", radius = NULL, palette = NULL, palette.reverse = TRUE, color = "red", show.subtitle = TRUE, show.plane = TRUE, plane.color = "steelblue", plane.alpha = 0.5, summarymode = 1, ... )
predict3d( fit, pred = NULL, modx = NULL, mod2 = NULL, dep = NULL, xlab = NULL, ylab = NULL, zlab = NULL, width = 640, colorn = 20, maxylev = 6, se = FALSE, show.summary = FALSE, overlay = NULL, show.error = FALSE, show.legend = FALSE, bg = NULL, type = "s", radius = NULL, palette = NULL, palette.reverse = TRUE, color = "red", show.subtitle = TRUE, show.plane = TRUE, plane.color = "steelblue", plane.alpha = 0.5, summarymode = 1, ... )
fit |
A model object for which prediction is desired. |
pred |
The name of predictor variable |
modx |
Optional. The name of moderator variable |
mod2 |
Optional. The name of second moderator variable |
dep |
Optional. The name of dependent variable |
xlab |
x-axis label. |
ylab |
y-axis label. |
zlab |
z-axis label. |
width |
the width of device |
colorn |
An integer giving the desired number of intervals. Non-integer values are rounded down. |
maxylev |
Maximal length of unique values of y axis variable to be treated as a categorical variable. |
se |
Logical. Whether or not show se. Only effective when the y-axis variable is a categorical one. |
show.summary |
Logical. Whether or not show statistical summary |
overlay |
Logical. Whether or not overlay plots |
show.error |
Logical. Whether or not show error |
show.legend |
Logical. Whether or not show legend |
bg |
Character. Background color of plot |
type |
For the default method, a single character indicating the type of item to plot. Supported types are: 'p' for points, 's' for spheres, 'l' for lines, 'h' for line segments from z = 0, and 'n' for nothing. For the mesh3d method, one of 'shade', 'wire', or 'dots'. Partial matching is used. |
radius |
The size of sphere |
palette |
Name of color palette |
palette.reverse |
Logical. Whether or not reverse the palette order |
color |
Default color. Color is used when the palette is NULL |
show.subtitle |
Logical. If true, show regression call as subtitle |
show.plane |
Logical. If true, show regression plane |
plane.color |
Name of color of regression plane |
plane.alpha |
Transparency scale of regression plane |
summarymode |
An integer indicating method of extracting typical value of variables. If 1, typical() is used.If 2, mean() is used. |
... |
additional parameters which will be passed to plot3d |
fit=lm(mpg~hp*wt,data=mtcars) predict3d(fit,show.error=TRUE) fit=lm(log(mpg)~hp*wt,data=mtcars) predict3d(fit,dep=mpg) ## Not run: fit=lm(Sepal.Length~Sepal.Width*Species,data=iris) predict3d(fit) require(TH.data) fit=glm(cens~pnodes*age*horTh,data=GBSG2,family=binomial) predict3d(fit) mtcars$engine=ifelse(mtcars$vs==0,"V-shaped","straight") fit=lm(mpg~wt*engine,data=mtcars) predict3d(fit) fit=loess(mpg~hp*wt,data=mtcars) predict3d(fit,radius=4) states<-as.data.frame(state.x77[,c("Murder","Population","Illiteracy","Income","Frost")]) fit=lm(Murder~Population+Illiteracy,data=states) predict3d(fit) predict3d(fit,radius=200) fit=lm(mpg~cyl+hp+am,data=mtcars) predict3d(fit) ## End(Not run)
fit=lm(mpg~hp*wt,data=mtcars) predict3d(fit,show.error=TRUE) fit=lm(log(mpg)~hp*wt,data=mtcars) predict3d(fit,dep=mpg) ## Not run: fit=lm(Sepal.Length~Sepal.Width*Species,data=iris) predict3d(fit) require(TH.data) fit=glm(cens~pnodes*age*horTh,data=GBSG2,family=binomial) predict3d(fit) mtcars$engine=ifelse(mtcars$vs==0,"V-shaped","straight") fit=lm(mpg~wt*engine,data=mtcars) predict3d(fit) fit=loess(mpg~hp*wt,data=mtcars) predict3d(fit,radius=4) states<-as.data.frame(state.x77[,c("Murder","Population","Illiteracy","Income","Frost")]) fit=lm(Murder~Population+Illiteracy,data=states) predict3d(fit) predict3d(fit,radius=200) fit=lm(mpg~cyl+hp+am,data=mtcars) predict3d(fit) ## End(Not run)
Rank a numeric vector using proportional table and returns character vector of names of color using palette
rank2colors(x, palette = "Blues", reverse = TRUE, color = "red")
rank2colors(x, palette = "Blues", reverse = TRUE, color = "red")
x |
A numeric vector |
palette |
Name of the color palette |
reverse |
Logical. Whether or not reverse the order of the color palette |
color |
Default color when palette is NULL |
rank2colors(mtcars$wt,palette="Blues")
rank2colors(mtcars$wt,palette="Blues")
Rank a numeric vector using proportional table and returns a new ordinal vector
rank2group2(x, k = 4)
rank2group2(x, k = 4)
x |
a numeric vector |
k |
a integer specifies how many groups you want to classify. default value is 4 |
Restore factors in data.frame as numeric
restoreData(data)
restoreData(data)
data |
A data.frame |
fit=lm(mpg~factor(cyl)*factor(am),data=mtcars) fit=lm(mpg~wt*factor(am),data=mtcars) fit=lm(mpg~wt*hp,data=mtcars) restoreData(fit$model)
fit=lm(mpg~factor(cyl)*factor(am),data=mtcars) fit=lm(mpg~wt*factor(am),data=mtcars) fit=lm(mpg~wt*hp,data=mtcars) restoreData(fit$model)
restore data column with I() function
restoreData2(df)
restoreData2(df)
df |
A data.frame |
fit=lm(mpg~I(cyl^(1/2))*am,data=mtcars) restoreData2(fit$model) fit=lm(mpg~sqrt(hp)*log(wt)*am,data=mtcars) restoreData2(fit$model)
fit=lm(mpg~I(cyl^(1/2))*am,data=mtcars) restoreData2(fit$model) fit=lm(mpg~sqrt(hp)*log(wt)*am,data=mtcars) restoreData2(fit$model)
Restore data from arithmetic operator
restoreData3(df, changeLabel = FALSE)
restoreData3(df, changeLabel = FALSE)
df |
A data.frame |
changeLabel |
logical |
fit=lm(2^mpg~hp*wt,data=mtcars) summary(fit) restoreData3(fit$model)
fit=lm(2^mpg~hp*wt,data=mtcars) summary(fit) restoreData3(fit$model)
Restore factors in variable name as numeric
restoreNames(x)
restoreNames(x)
x |
character vector |
restoreNames(c("factor(cyl)","am")) restoreNames(c("I(age^2)","am","100/mpg","cyl^1/2","mpg2","sex + 0.5"))
restoreNames(c("factor(cyl)","am")) restoreNames(c("I(age^2)","am","100/mpg","cyl^1/2","mpg2","sex + 0.5"))
get opposite arithmetic operator
revOperator(operator)
revOperator(operator)
operator |
A character |
Find variable names in data.frame
seekNamesDf(vars, df)
seekNamesDf(vars, df)
vars |
variable names to find |
df |
A data.frame |
A character vector
Create a sequence over the range of a vector
seq_range(x, n = 2)
seq_range(x, n = 2)
x |
A numeric vector |
n |
An integer specifying the length of sequence (i.e., number of points across the range of x) |
seq_range(1:5,n=3)
seq_range(1:5,n=3)
Make angle data with slope data
slope2angle( df, fit, ytransform = 0, predc, temppredc, modxc, yvar, p, method = "lm", xpos = NULL, vjust = NULL, digits = 3, facetno = NULL, add.modx.values = TRUE )
slope2angle( df, fit, ytransform = 0, predc, temppredc, modxc, yvar, p, method = "lm", xpos = NULL, vjust = NULL, digits = 3, facetno = NULL, add.modx.values = TRUE )
df |
A data.frame |
fit |
An object of class "lm" or "glm" |
ytransform |
Numeric. If 1, log transformation of dependent variable, If -1, exponential transformation |
predc |
Name of predictor variable |
temppredc |
Name of predictor variable in regression equation |
modxc |
Name of moderator variable |
yvar |
Name of dependent variable |
p |
An object of class ggplot |
method |
String. Choices are one of "lm" and "glm". |
xpos |
The relative x-axis position of labels. Should be within 0 to 1 |
vjust |
vjust |
digits |
integer indicating the number of decimal places |
facetno |
The number of facets |
add.modx.values |
Whether add name of moderator variable |
change string to pattern
string2pattern(string)
string2pattern(string)
string |
A character vector |
string=c("I(age^2)","factor(cyl)","log(mpg)") string2pattern(string)
string=c("I(age^2)","factor(cyl)","log(mpg)") string2pattern(string)