I am currently generating simple linear regression plots in ggplot2 with the following code (toy example)
library(ggplot2)
Data<-data.frame(Age=c(40,41,42,43,44,45,46,47,48,49),
Height=c(185,184,183,182,181,186,187,188,189,190),
Sex=c("Male","Male","Male","Male","Male","Female","Female","Female","Female","Female"),
Weight=c(84,83,82,81,80,85,86,87,88,89),
BMI=c(20,21,22,23,24,25,26,27,28,29))
points<-c("#FF9999","turquoise")
lines<-c("dark red","blue")
linetypes<-c(1,1)
x<-ggplot(Data,aes(x=Age,y=Weight))+
geom_point(aes(fill=factor(Sex)),size=4,alpha=1,shape=21,color="transparent")+
geom_smooth(aes(color=Sex,linetype=Sex),method="lm",formula=y~x,lwd=1,se=F)+
scale_fill_manual(values=points,labels=c("Female","Male"))+
scale_colour_manual(values=lines)+
scale_linetype_manual(values=linetypes)+
theme_classic(base_size=15)+
theme(legend.position="top",legend.direction="horizontal")+
labs(fill="Points",colour="Lines",x='Age',y='Weight')+
guides(fill=guide_legend(override.aes=list(shape=c(16,16),alpha=1,size=4,color=c("#FF9999","turquoise"))))+
guides(colour=guide_legend(override.aes=list(linetype=c(1,1),alpha=1,size=1,color=c("dark red","blue"))))+
guides(linetype="none")
x
I am stuck as how to add one-or-more covariates, in order to transform the plots from simple to multiple linear regression, e.g., from
Weight~Age to Weight~Age+Height+BMI
I am sure that it must have something to do with the method="lm" and formula=y~x commands, but I am not clear on exactly what changes need to be made.
Any help would be very much appreciated. Thank you.
In order to strengthen the interpretation of an interaction term I would like to create an interaction plot.
Starting Point: I am analyzing a panel data frame with which I fitted a feasible generalized least squares model by using the panelAR function. It includes an interaction term of two continuous variables.
What I want to do: To create an interaction plot, e.g. following the style of “plot_model” from the package sjPlot (see Three-Way-Interactions: link).
Problem: I could neither find any package which supports the type of my model nor a different way to get a plot.
Question: Is there any workaround which can be used for obtaining an interaction plot or even a package which supports a panelAR model?
Since I am quite new to R I would appreciate every kind of help. Thank you very much
I have constructed a model of svm on a dataset of Fraud transactions , but when I am trying to plot the model it is neither showing any error nor showing any plot. My code is -
>library(e1071)
>attach(FraudTransData)
>model2<- svm(FraudTransData$Fraud_Ind~., data= FraudTransData)
>plot(model2, FraudTransData)
I used the same plot function on another dataset cats and it showed a successful plot. I am unable to understand where have I gone wrong.
How many inputs do you have?
The code you wrote does not work if you have more than two. You should add arguments formula and slice in the plot function.
Check the 'iris' example at help(plot.svm)
I'm using the fourier() and fourierf() functions in Ron Hyndman's excellent forecast package in R. Looking to verify whether the same terms are selected and used in fourier() and fourierf(), I plotted a few of the output terms.
Below is the original data using ts.plot(data). There's a frequency of 364 in the time series, FYI.
Below is the plot of the terms using fourier(data,3). Basically, it looks like mirror images of the existing data.
Looking at just the sin1 term of the output, again, we get some variation that shows similar 364-day seasonality in line with the data above.
However, when I plot the results of the Fourier forecast using fourierf(data,3, 410) I see the below data. It appears far more smooth than the terms provided by the original fourier function.
So, I wonder how the results of fourier() and fourierf() are related. Is it possible to just see one consolidated Fourier result, so that you can see the sin or cosine result moving through existing data and then through the forecasting period? If not, how can I confirm that the terms created by fourierf() fit the in-sample data?
I want to use it in an auto.arima or glm function with other external regressors like this:
trainFourier<-fourier(data,3)
trainFourier<-as.data.frame(trainFourier)
trainFourier$exogenous<-exogenousData
arima.object<-auto.arima(data, xreg=trainFourier)
futureFourier<-fourierf(data,3, 410)
fourierForecast<-forecast(arima.object, xreg=futureFourier, h=410)
and want to be completely sure that the auto.arima has the proper fitting (using the terms from fourier()) to what I'll put in under xreg for forecast (which has terms from a different function, i.e. ffourier()).
Figured out the problem. I was using both the fda and forecast packages. fda, which is for functional data analysis and regression, has its own fourier() function. If I detach fda, my S1 term from fourier(data,3) looks like this:
which lines up nicely with the Fourier forecast if I use ts.plot(c(trainFourier$S1,futureFourier$S1))
Moral of the story -- watch what your packages supress, folks!
I am not really sure about the difference between CDF (Cumulative Distribution Function) and ECDF (Empirical Cumulative Distribution Function) but I usually utilize a CDF plot to make observations about my data.
I have been using R recently and am desperately trying to find out how to plot a CDF and CCDF (Complementary CDF) of my data. All I could find was that R has ecdf but am not really sure if this is what I am looking for. Plotting an ECDF is as simple as:
plot.ecdf(data)
Does anyone know how to plot a CDF and CCDF of a dataset using R?
A CDF commonly requires closed form when you know or assume a distribution. An ECDF, on the other hand, is 'empiricial' as it comes from your data. I just answered a question about using ecdf() and Hmisc's Ecdf() here the other day.
More generally, you can search here using terms such as
[r] ecdf
in the search box to look for 'ecdf' within the R tag. At rseek.org, little comes up for 'ccdf'. Is that maybe just the same as one minus the ECDF? If so, Ecdf() in Hmisc can do it.
I hope this helps, if not please re-phrase your question as it is not quite clear exactly what you are looking for. Both ecdf() and Ecdf() are pretty featureful so make sure to read their help pages.