log2 issue when doing Survival Analysis - r

I am planning to use TCGAbiolinks to perform an survival analysis by using the following code:
library(TCGAbiolinks)
library(SummarizedExperiment)
query_RNAseq <- GDCquery(project = "TCGA-PAAD",
data.category = "Gene expression",
data.type = "Gene expression quantification",
platform = "Illumina HiSeq",
file.type = "results",
experimental.strategy = "RNA-Seq",
legacy = TRUE)
GDCdownload(query_RNAseq, method = "api",chunks.per.download = 10)
PAADRnaseqSE <- GDCprepare(query_RNAseq)
# Survival Analysis SA
clinical_patient_Cancer <- GDCquery_clinic("TCGA-PAAD","clinical")
dataPAADcomplete <- log2(PAADRnaseqSE)
but it produced an error when I run the log2 function, code and error info are pasted below
> dataPAADcomplete <- log2(PAADRnaseqSE)
Error in log(<S4 object of class "RangedSummarizedExperiment">, 2) :
unused argument (2)
What should I do to solve the problem?

Related

How do I resolve an integration error in Seurat?

I am new to Seurat, and am trying to run an integrated analysis of two different single-nuclei RNAseq datasets. I have been following the Seurat tutorial on integrated analysis (https://satijalab.org/seurat/articles/integration_introduction.html) to guide me, but when I ran the last line of code, I got an error.
# Loading required libraries
library(Seurat)
library(cowplot)
library(patchwork)
# Set up the Seurat Object
vgat.data <- Read10X(data.dir = "~/Desktop/VGAT Viral Data 1/")
vglut.data <- Read10X(data.dir = "~/Desktop/VGLUT3 Viral/")
# Initialize the Seurat object with the raw (non-normalized data)
vgat <- CreateSeuratObject(counts = vgat.data, project = "VGAT/VGLUT Integration", min.cells = 3, min.features = 200)
vglut <- CreateSeuratObject(counts = vglut.data, project = "VGAT/VGLUT Integration", min.cells = 3, min.features = 200)
# Merging the datasets
vgat <- AddMetaData(vgat, metadata = "VGAT", col.name = "Cell")
vglut <- AddMetaData(vglut, metadata = "VGLUT", col.name = "Cell")
merged <- merge(vgat, y = vglut, add.cell.ids = c("VGAT", "VGLUT"), project = "VGAT/VGLUT Integration")
# Split the dataset into a list of two seurat objects (vgat and vglut)
merged.list <- SplitObject(merged, split.by = "Cell")
# Normalize and Identify variable features for each dataset independently
merged.list <lapply(X = merged.list, FUN = function(x) {
x <- NormalizeData(x)
x <- FindVariableFeatures(x, selection.method = "vst", nFeatures = 2000)
})
After running the last line of code, I get the following error: Error in merged.list < lapply(X = merged.list, FUN = function(x) { :
comparison of these types is not implemented
I was wondering if anyone is familiar with Seurat and knows how I can troubleshoot this error. Any help would be greatly appreciated.

Error during wrapup: $ operator is invalid for atomic vectors

I keep getting this error message, I am not too sure what went wrong as I am trying to do a linear regression analysis.
Ind_v is the independent variable and dep_v is the dependent variable. I switched the data.frame to [] and it doesn't work as well. Thank you so much, everyone!
I split the training and test data to 70/30.
linear_regression <- function(training_dataset,
test_dataset,
dependent_variables,
independent_variables){
formular_me <- paste(dependent_variables, "~", independent_variables)
linear_model <- lm(formula = formular_me, data = training_dataset)
ind_v_from_test_dataset <- subset(test_dataset,select=independent_variables)
linear_model_analysis <- predict(linear_model,ind_v_from_test_dataset)
dep_v_from_test_dataset <- test_dataset[,dependent_variables]
RMSE_me <- round(Nrmse(actual = dep_v_from_test_dataset, predicted = linear_model_analysis),digits=2)
MAE_me <- round(Nmae(actual = dep_v_from_test_dataset,predicted = linear_model_analysis),digits=2)
R2_me <- round(Nr2(linear_model_analysis),digits=2)
linear_analysis_error <- dep_v_from_test_dataset - linear_model_analysis
linear_results<- data.frame(dep_v_from_test_dataset,ind_v_from_test_dataset,linear_analysis_error)
linear_results<- linear_analysis_error[order(ind_v_from_test_dataset),]
plot(linear_results[,independent_variables],
linear_results$ind_v_from_test_dataset,
pch=4,
ylab="dependent variable",
xlab="independent variables",
main="Linear Regression Errors",
sub=paste("MAE=",mae,"RMSE=",RMSE," R2=",r2))
abline(linear_model,col = "blue", lwd=6)
suppressWarnings(arrows(linear_results[,ind_v_from_test_dataset],
linear_results$dep_v_from_test_dataset,
linear_results[,independent_variables],
linear_results$dep_v_from_test_dataset-linear_results$error,
length=0.05,angle=90,code=3,col="red"))
return(
list(RMSE_me=RMSE,
MAE_me=mae,
R2_me=r2))
}

Error in gam function in R

I have a problem with my R code about a multiple linear regression.
First, I try to use the gam function but this gives me an error.
Here is the code:
install.packages("nlme")
library("mgcv")
library("ggplot2")
#Import dataset
setwd("/Users/Sarah/Documents/Master T&O/Master 1/Statistics IV/Assignment 2 ")
weight_data = read.csv("WeightLossGroup190.csv", sep = "", dec = ".", header = TRUE)
#Name of used data
weight <- weight_data$weight
date <- weight_data$date
dayNr <- weight_data$dayNumber
time <- weight_data$time
#Check linearity
gam1 <- gam(as.numeric(weight_data$weight) ~ s(as.numeric(weight_data$dayNumber)) + s(as.numeric(weight_data$time)))
summary(gam1)
plot.gam(gam1, se = FALSE, rug = TRUE, all.terms = TRUE)
This gives me the following error:
Error in smooth.construct.tp.smooth.spec(object, dk$data, dk$knots) :
A term has fewer unique covariate combinations than specified maximum degrees of freedom
Does anyone have an idea of what I'm doing wrong?
You might want to try controlling the number of knots with "k = " in the gam.

R : How to deal with "non-unique row.names given" in "predict.sarlm"

I'm facing an error in R trying to predict a sac model with new data. I'm using the following code:
# I've fitted a sac model and now I'm trying to predict for a new dataset:
>newdata = read.csv("location" , header=T , sep=",")
#Calculate the new matrix from this new data:
>cord <- coordinates(newdata[,c("X","Y")])
>k1 <- knn2nb(knearneigh(cord, k=5))
>all.linked <- max(unlist(nbdists(k1, cord)))
>d <- dnearneigh(cord, 0, all.linked)
>dlist <- nbdists(d, coordinates(cord))
>wn = nb2listw(d, glist=dlist, style="W")
#predict:
>prediction = predict.sarlm(sac_model, newdata = newdata, pred.type = "TC", wn )
Here's where the problem appears:
Error in mat2listw(W, row.names = region.id, style = style) : non-unique row.names given
Honestly, I can't see where is the error in the code.

XGBoost - predict not exported in namespace

I am trying to tune an xgboost model with a multiclass dependent variable in R. I am using MLR to do this, however I run into an error where xgboost doesn't have predict within its namespace - which I assume MLR wants to use. I have had a look online and see that other people have encountered similar issues. However, I can't entirely understand the answers that have been provided (e.g. https://github.com/mlr-org/mlr/issues/935), when I try to implement them the issue persists. My code is as follows:
# Tune parameters
#create tasks
train$result <- as.factor(train$result) # Needs to be a factor variable for makeClass to work
test$result <- as.factor(test$result)
traintask <- makeClassifTask(data = train,target = "result")
testtask <- makeClassifTask(data = test,target = "result")
lrn <- makeLearner("classif.xgboost",predict.type = "response")
# Set learner value and number of rounds etc.
lrn$par.vals <- list(
objective = "multi:softprob", # return class with maximum probability,
num_class = 3, # There are three outcome categories
eval_metric="merror",
nrounds=100L,
eta=0.1
)
# Set parameters to be tuned
params <- makeParamSet(
makeDiscreteParam("booster",values = c("gbtree","gblinear")),
makeIntegerParam("max_depth",lower = 3L,upper = 10L),
makeNumericParam("min_child_weight",lower = 1L,upper = 10L),
makeNumericParam("subsample",lower = 0.5,upper = 1),
makeNumericParam("colsample_bytree",lower = 0.5,upper = 1)
)
# Set resampling strategy
rdesc <- makeResampleDesc("CV",stratify = T,iters=5L)
# search strategy
ctrl <- makeTuneControlRandom(maxit = 10L)
#parallelStartSocket(cpus = detectCores()) # Enable parallel processing
mytune <- tuneParams(learner = lrn
,task = traintask
,resampling = rdesc
,measures = acc
,par.set = params
,control = ctrl
,show.info = T)
The specific error I get is:
Error: 'predict' is not an exported object from 'namespace:xgboost'
My package versions are:
packageVersion("xgboost")
[1] ‘0.6.4’
packageVersion("mlr")
[1] ‘2.8’
Would anyone know what I should do here?
Thanks in advance.

Resources