createDataPartition function not working in Rstudio - r

code:
validation_index <- createDataPartition(dataset$Accepectance.Rate, p=0.80, list=FALSE)
Error in createDataPartition(dataset$Accepectance.Rate, p = 0.8, list = FALSE) :
could not find function "createDataPartition"
My dataset is of 400 observations and 8 variables.
Could anyone suggest what's wrong with this, although I have install the required packages

You have to use library or require after installing if you want to use a function from the package caret. For example:
library(caret)
or
require(caret)
should be run before you use the function createDataPartition()
You can also use the function as caret::createDataPartition().

Related

Argument 3 matches multiple formal arguments with ‘mediate’ function using ‘psych’ package

Please help! Trying to conduct a mediation model using the psych package following the code below. It worked originally and now I keep getting the error
argument 3 matches multiple arguments
require(psych)
Mediation1<-mediate(“lifestyle", "Gender", m=c(“smoker"), data= lifedata, std=TRUE, n.iter=5000, plot= F)
Mediation1
Have you tried making sure it is through the psych package?
I got the same error when it was automatically being run through the mediation package.
Try psych::mediate(“lifestyle", "Gender", m=c(“smoker"), data= lifedata, std=TRUE, n.iter=5000, plot= F)
Hope that helps you!

CARET Package in R - createDataPartition() function not found?

I am learning the CARET Package in R and I am trying to run to code in Max Kuhn's paper "A Short Introduction to the caret Package". When I run the following code, after successfully installing CARET:
data(Sonar)
set.seed(107)
# The outcome data are needed, the percentage of data in the training set & the format of the results
inTrain <- createDataPartition(y = Sonar$Class,p = .75, list = FALSE)
str(inTrain)
I get the following error that this function createDataPartition() is not found:
Error in createDataPartition(y = Sonar$Class, p = 0.75, list = FALSE) :
could not find function "createDataPartition"
> str(inTrain)
Error in str(inTrain) : object 'inTrain' not found
Any thoughts?
Best,
Mike
I had the same problem... The solution:
In your shell go to /var/folders/tn/f7md6x8j0b73tg9tp83hgm4r0000gn/T//RtmpChzV5D/downloaded_packages
cd /var/folders/tn/f7md6x8j0b73tg9tp83hgm4r0000gn/T//RtmpChzV5D/downloaded_packages
Look what you have there:
ls
If you have something like caret_6.0-80.tgz, you need to remove it:
sudo rm -r caret_6.0-80.tgz
I hope I've helped :)

Imputation of missing data: mice gives erratic results in R

I am running some simple code with the mice function for imputation of missing data, using the library mice.
I run the code with the airquality dataset (base R) without a problem, but when I run the same code using another dataset from base R --mtcars--I am getting an error ("undefined columns selected"). See below:
The code as text is the following:
library(dplyr)
library(mice)
data = airquality
data[4:10,3] = rep(NA,7)
data[1:5,4] = NA
summary(data)
tempData = mice(data,m=5,maxit=50,meth='pmm',seed=500)
data(mtcars)
mtcars[mtcars$am == 1, "am"] = NA
data1 = mtcars[, c(2:11)]
summary(data1)
tempData = mice(data1,m=5,maxit=50,meth='pmm',seed=144)
I am confused. Why the same code works in the former case and then does not work in the latter?
Your advice will be appreciated.
Edit
Indeed I installed the latest version of Mice from CRAN and the code run without a problem

R Leaps Package: Regsubsets - coef "Reordr" Fortran error

I'm using the R leaps package to obtain a fit to some data:
(My dataframe df contains a Y variable and 41 predictor variables)
require(leaps)
N=3
regsubsets(Y ~ ., data = df, nbest=1, nvmax=N+1,force.in="X", method = 'exhaustive')-> regfit
coef(regfit,id = N)
When I run the code more than once (the first time works fine) I get the following error when I run the coef command:
Error in .Fortran("REORDR", np = as.integer(object$np), nrbar = as.integer(object$nrbar), :
"reordr" not resolved from current namespace (leaps)
Any help with why this is happening would be much appreciated.
A.
I had to build the package from source inserting the (PACKAGE = 'leaps') argument into the REORDR function in the leaps.R file. It now works fine every time.
The solution is related to:
R: error message --- package error: "functionName" not resolved from current namespace

Issue with cross-validation using the automap package

I want to do a cross-validation for the ca20-Dataset from the geoR
package. With for example the meuse-dataset, this works fine, but for
this dataset, I encounter a strange problem with the dimensions of the
SpatialPointsDataFrame. Maybe you can try this for yourself and explain
why the autoKrige.cv function does not work (I tried several
nfold-values but this only changes the locations-value of the error
message...):
library(geoR)
library(gstat)
library(automap)
data(ca20)
east=ca20$coords[,1]
north=ca20$coords[,2]
concentration=ca20$data
frame=data.frame(east,north)
data=data.frame(concentration)
points<-SpatialPoints(data.frame(east,north),proj4string=CRS(as.character(NA)))
pointsframe<-SpatialPointsDataFrame(points,data, coords.nrs = numeric(0),proj4string = CRS(as.character(NA)), match.ID = TRUE)
krig=autoKrige(pointsframe$concentration~1,pointsframe)
plot(krig)
cv=autoKrige.cv(pointsframe$concentration~1,pointsframe)
I hope someone can reproduce the problem, my R version is 2.15, all packages are up to date (at least not older than a month or so...).
Thanks for your help!!
First, the way you build your SpatialPointsDataFrame can be done more easily:
library(geoR)
library(gstat)
library(automap)
...and build the SPDF:
pointsframe = data.frame(ca20$coords)
pointsframe$concentration = ca20$data
coordinates(pointsframe) = c("east", "north")
The problem you have is in how you use the formula argument. You add the spatial object pointsframe to the formula, in essence putting a vector directly into the formula. You should just use the column name in the formula, like this:
cv=autoKrige.cv(concentration~1,pointsframe)
and it works:
> summary(cv)
[,1]
mean_error -0.01134
me_mean -0.0002237
MAE 6.02
MSE 60.87
MSNE 1.076
cor_obspred 0.7081
cor_predres 0.01343
RMSE 7.802
RMSE_sd 0.7041
URMSE 7.802
iqr 9.519

Resources