'R - Error in outx$coefficients["x", 4] : subscript out of bounds
I want to apply the lin.mod linear regression model to calculate linear regression between gc.trans trans-acting snps and expr gene expression values.
> # Extract all of the SNPs on chromosome 14 except for the SNPs cis to DICER 1
> t.snp <- dplyr::filter(map, V1==14 & ! V2 %in% snps)
> dim(t.snp)
[1] 303 4
> # Find the positions of the trans-acting SNPs
> p2.trans <- (as.numeric(rownames(t.snp))*2)+6
> p1.trans <- p2.trans-1
>
> # Subset the pedigree file by the positions of the trans-acting SNPs
> pc.trans <- ped[,p1.trans]
>
> # Convert the SNPs from a 2 allele genotype code to a single 1 number genotype code
> gc.trans <- apply(pc.trans, 1, recode)
>
> # Linear regression model
> lin.mod <- function(x,y) {
+ x <- as.numeric(x)
+ dat <- data.frame(y, x)
+ out <- lm(y~x, data=dat)
+ outx <- summary(out)
+ return(outx$coefficients["x",4])
+ }
> lr.trans <- apply(gc.trans, 1, lin.mod, t(expr))
Traceback:
Error in outx$coefficients["x", 4] : subscript out of bounds
Map
> dput(map[1:10,])
structure(list(V1 = c(15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L), V2 = c("SNP_A-1850451", "SNP_A-1910129", "SNP_A-1793338",
"SNP_A-1938260", "SNP_A-2269619", "SNP_A-2246474", "SNP_A-2275061",
"SNP_A-1961089", "SNP_A-2131173", "SNP_A-4227303"), V3 = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), V4 = c(41361016L, 41366515L,
41386408L, 41396801L, 41410208L, 41419430L, 41440229L, 41446338L,
41449654L, 41455192L)), row.names = c(NA, 10L), class = "data.frame")
snps
> dput(snps)
c("SNP_A-2240938", "SNP_A-2249234", "SNP_A-2120212", "SNP_A-1864785",
"SNP_A-1944204", "SNP_A-2101022", "SNP_A-2192181", "SNP_A-4296300",
"SNP_A-1961028", "SNP_A-2215249", "SNP_A-2172180", "SNP_A-1945117",
"SNP_A-1941491")
ped
> dput(ped[,1:10])
structure(list(V1 = c("AC1", "AC2", "AC5", "AC6", "AC8", "AC13",
"AC14", "AC15", "AC16", "AC18", "AC19", "AC20", "AC21", "AC23",
"AC24", "AC27", "AC29", "AC30", "AC33", "AC34", "AC35", "AC36",
"AC38", "AC42", "AC43", "AC46", "AC49", "AC51", "AC52", "AC53",
"AC54", "AC56", "AC57", "AC58", "AC60", "AC61", "AC62", "AC63",
"AC65", "AC67", "AC69", "AC70", "AC71", "AC72", "AC74", "AC76",
"AC77", "AC79", "AC80", "AC83", "AC84", "AC86", "AC89", "AC90",
"AC95", "AC96", "AC99", "AC32", "AC102", "AC104", "AC103", "AC105",
"DE45", "DE13", "DE52", "DE51", "DE50", "DE23", "DE7", "DE36",
"DE22", "DE32", "DE14", "DE27", "DE10", "DE4", "DE46", "DE3",
"DE16", "DE40", "DE39", "DE17", "DE59"), V2 = c(1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L),
V3 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 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L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), V10 = c(2L,
2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L,
2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L)), class = "data.frame", row.names = c(NA,
-83L))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
