I have seen some other posts on here but after going through them Im not finding a solution. I am using limma to do DE analysis on 763 patient microarrays, 4 groups total. My expression object is a matrix with rownames as genes and colnames as patient ID.
When I try to run the code I get the error:
> fit <- lmFit(as.numeric(Merge_DF_Avg2), design)
Error in lmFit(as.numeric(Merge_DF_Avg2), design) :
row dimension of design doesn't match column dimension of data object
The dimensions seem correct:
> dim(design)
[1] 763 4
> dim(Merge_DF_Avg2)
[1] 20341 763
> class(Merge_DF_Avg2)
[1] "matrix" "array"
Here is the code:
#Data wrangle for limma
>Merge_DF_Avg <-readRDS("C:/Users/12298/Desktop/Data_Analytics/Taylor_2017/Finalized_Expression_Array_avgs.rds")
>Merge_DF_Avg2 <- Merge_DF_Avg %>% na.omit() %>% pivot_wider(values_from=avg, names_from=Gene_Name) %>% t() %>% janitor::row_to_names(row_number = 1)
>Patient_Cat <- as.vector(as.numeric(Merge_DF_Avg2[1,]))
>Merge_DF_Avg2 <- Merge_DF_Avg2[-c(1,2),] #Taking out patient cat and unidentified gene rows
#limma design
>design <- model.matrix(~ 0 + factor(Patient_Cat))
>colnames(design) <- c("SHH", "Group3", "Group4", "WNT")
>fit <- lmFit(as.numeric(Merge_DF_Avg2), design)
I am using the example code provided by the limma package pdf to guide me.
In general, please make it a habit in the future to provide the data using
dput
(at least a small chunk of it) to allow reproduction of the problem.I already have an answer to the post but I would like to know more about this. When I post should I just copy and paste the output from dput? For this matrix its a bit chaotic since there are 763 columns. The output gets cut off in the console because its so long.
A small subset of the data is a good idea so one can actually run the code you provide. Yes, just copy paste the dput, one can then easily paste this back into R.