How to install ROCR package in R? - r

I want to plot a ROC curve using the ROCR package in R. I am trying to install the required package but unable to install it. Is there any alternate way of plotting the ROC curve?

There are some awesome packages for creating ROC Plots and Curves. The three most popular packages are pROC, ROCR and PPROC.
Each package has a different method for generating the plot. Here is a good website to see how to do it for each of these six packages: Some R Packages for ROC Curves.
Here is a good way to see which packages are the most popular:
library(dlstats)
library(dplyr)
shortList <- c("pROC","precrec","ROCit","PRROC","ROCR","plotROC")
downloads <- cran_stats(shortList)
ggplot(downloads, aes(end, downloads, group=package, color=package)) +
geom_line() +
geom_point(aes(shape=package)) +
scale_y_continuous(trans = 'log2') +
scale_x_date(date_labels="%Y", breaks="years") +
labs(title="Downloads Per Package Over Time"
,y="Downloads Per Month (log2)"
,x="Time"
,caption="Souce: \'https://cranlogs.r-pkg.org/downloads/total\'.\nAccessed via package: \'dlsatats\'."
)
This plot looks like this:
I trust that helps?

In RStudio in the bottom right window (window that shows: Files | Plots | Packages etc)
Click on "Packages"
Then Install
In the pop-up window :
Install from: "Repository (CRAN)" then Packages: "ROCR" then tick INSTALL DEPE.. then click INSTALL

Related

Issue installing packages "labeling" and "scales" in RStudio 2022.02.3

I usually plot my data with the following ggplot syntax:
ggplot(sent.TN.yr.avg, aes(y = (log10(mean)), x = YEAR, color = ECOREGION)) +
geom_point(size = 1, alpha = 0.4) +
geom_smooth(se=TRUE) +
xlab(expression(paste("Year"))) + ylab(expression(paste("Mean TN (", mu, "g", L^-1,")"))) +
theme_light()
But this recently led me to the following loadnamespace(name) error:
Error in loadNamespace(x) : there is no package called ‘labeling’
I'm not sure how this code prompted an error related to "labeling." Still, I tried restarting RStudio and installing that, but it cannot be supported by this version of RStudio (2022.02.3). I also tried the same thing with the "scales" package and got the same result. I've also tried changing the repository to different CRAN mirrors with no success.
Any tips?
Package ggplot2 imports package scales which imports package labeling. So in order to use ggplot you should have installed the other two packages as well.
The version of RStudio most likely has nothing to do with it. But if you recently switched from R version 4.1.* to R4.2.* you have to upgrad all your installed packages (they have to be recompiled after a major R version release).
You can do this in RStudio: Tools -> Check for Package Updates...
or directly in R with: update.packages(checkBuilt = TRUE)
By the way, on the ggplot2 page there is an example of how mathematical expressions can be inserted into axis labels:
https://ggplot2.tidyverse.org/articles/faq-axes.html?q=superscript#how-can-i-add-superscripts-and-subscripts-to-axis-labels

how do I create a probability plot in R using R-studio

I want to create a lognormal (or other distribution) probability plot in R (for R-studio). I have looked around on the web for an example but none of the examples tell me what package I need to install in order to use the function.
logn_prob_plot <- function()
{
x<-rlnorm(10,5,1)
x
probplot(x,qdist=qlnorm,xlab="failure time",ylab="lognormal probability")
}
Error in probplot(x, qdist = qlnorm, xlab = "failure time", ylab = "lognormal probability") : could not find function "probplot"
Writing up the comment thread as an answer:
The error (could not find function "probplot") is showing up because a necessary package is not installed. It's not specifically related to creating a probability plot.
Googling "r probplot" turns up the documentation for the package e1071, which is available in CRAN.
The package can be installed by entering install.packages("e1071") in your terminal or by selecting Tools -> Install Packages in the RStudio GUI. You can then load that package using library("e1071").

Points3D Function in R

I have the scatterplot3d package installed in R. When I load it with library(scatterplot3d) or require(scatterplot3d) I am able to create a 3d scatter plot. However, when I try to use the points3d function I get the following error:
Error: could not find function "points3d"
I tried reinstalling the package to no avail (both inside R and as a tarball using R CMD INSTALL in the command line). I am running Xubuntu 12.10 kernel 3.8.7-030807-generic and R version 2.15.3 (2013-03-01).
Entering locate points3d in the command line gave me no results.
I also tried the par.mar default settings command as explained in the manual.
scatterplot3d does an interesting object-oriented twist on the usual R practice. The object returned from the function call includes the points3d function as built-in part of the object but it is not in the Global environment. It is intended that you add to the existing plot-object using that "attached" function that is not a free-living organism but rather a domesticated animal that only exists in the object corral, so you would use this as your syntax:
object$point3d(x,y,z)
I do "feel your pain" but can show you how to overcome the frustration, since I created a working example yesterday: Using scatterplot3d to plot a sphere
You need to intall the package plot3D in the usual way via
install.packages("plot3D")
Then you just need to import, generate the dataset and use the function points3D()
library(plot3D)
x = rnorm(100)
y = rnorm(100)
z = x + y + rnorm(100,0,1)
points3D(x, y, z, col = rainbow(1000))
This is the plot generated by the code above

pscl package of R

I was running the xyplot of presidential elections in the pscl package and got the error
data(presidentialElections)
library(lattice)
xyplot(demVote ~ year | state,
panel=panel.lines,
ylab="Democratic Vote for President (percent)",
xlab="Year",
data=presidentialElections,
scales=list(y=list(cex=.6),x=list(cex=.35)),
strip=strip.custom(par.strip.text=list(cex=.6)))
Error:
Error in recordGraphics(drawGrob(x), list(x = x), getNamespace("grid")) :
invalid graphics state
I am a new user to R and would appreciate if anyone can help me to fix the error.
Try dev.off() and then re-run the same code.
I personally use tinn r to program in R and find it very useful, you can close/open R easily and still send command lines in. (you can even DL different versions of R to load for different packages)

Interface between Octave and R

Could anyone kindly update the status on the interface between Octave and R? ROctave package was developed in 2002, but no new updates after that. I like to call some functions from Octave in R such as "roots". How to do it?
Thanks for your help.
Expanding on chl's point of using R directly, you can also consider these CRAN packages which explicitly bring Octave functionality to R:
pracma
signal
And then there is the old but trusted R / Octave cheat sheet.
Edit in 2012 There is now also an emerging CRAN package RcppOctave which permits R to execute Octave code. The package is at a reasonably early stage, and works so far only on Unix.
I do not know of any active R/octave project, but if you're just after finding roots for a given polynomial you can use one of the polynom or PolynomF package:
Here is an example with P(x)= 6 + 5*x + 4*x^2 + 3*x^3 + 2*x^4 + x^5.
In octave,
octave[2] > p = 1:6;
octave[3] > roots(p)
ans =
0.55169 + 1.25335i
0.55169 - 1.25335i
-1.49180 + 0.00000i
-0.80579 + 1.22290i
-0.80579 - 1.22290i
In R,
> library(polynom)
> p <- polynomial(6:1)
> pz <- solve(p)
> pz
[1] -1.491798+0.000000i -0.805786-1.222905i -0.805786+1.222905i
[4] 0.551685-1.253349i 0.551685+1.253349i
I found this CRAN package called RcppOctave:
"Direct interface to Octave. The primary goal is to facilitate the port of Matlab/Octave scripts to R. The package enables to call any Octave functions from R and as well as browsing their documentation, passing variables between R and Octave, using R core RNGs in Octave, which ensure stochastic computations are also reproducible."
http://cran.r-project.org/web/packages/RcppOctave/index.html

Resources