2016-05-04 17 views
0

Ich habe ein Stück R-Code wie folgt, gibt es etwa 256 Koeffizienten durch Blick auf die Zusammenfassung Ausgang, im Grunde, was ich tun möchte, ist die NA-Koeffizienten zu entfernen (aufgrund von Singularitäten ?) und belasse die R-Ausgabe mit 64 Koeffizienten mit Schätzungen.entfernen Singularitäten, "NAs" von R Ausgabe

options (contrasts = c("contr.helmert", "contr.treat")) 
A <- factor(rep(c(-1,+1), 32)) 
B <- factor(rep(rep(c(-1, +1), rep(2,2)), 16)) 
C <- factor(rep(rep(c(-1, +1), rep(4,2)),8)) 
D <- factor(rep(c(-1, +1), rep(8,2))) 
E <- factor(rep(c(-1,+1),rep(16,2))) 
F <- factor(rep(c(-1,+1),rep(32,2))) 
G <- factor(c(1,-1,-1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ,-1 ,-1 ,1 ,1 ,-1 ,-1 ,1 ,-1 ,1 ,1 ,-1 ,-1 ,1 ,1 ,-1, 1 ,-1, -1, 1 ,1 ,-1, -1, 1, -1, 1, 1, -1, -1, 1 ,1 ,-1 ,1 ,-1 ,-1 ,1 ,1 ,-1 ,-1 ,1 ,-1 ,1 ,1 ,-1 ,-1 ,1 ,1 ,-1, 1, -1, -1, 1)) 
H <- factor(c(1 ,-1 ,-1, 1 ,-1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, 1, -1, -1, 1 ,-1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1)) 
response <-c(1492.868, 1436.853, 1885.51, 1874.33, 1663.626, 1510.596, 1858.447, 1973.903, 1838.914, 1843.337, 1990.952, 2111.174, 1899.739, 1950.174, 2193.745, 2202.168, 1557.929, 1410.439, 1899.71, 1794.309, 1606.785, 1631.428, 1856.971, 1920.209, 1902.78, 1912.863, 2130.872, 2207.799, 1928.437, 1999.139, 2326.517, 2218.633, 1362.776, 1622.451, 1756.323, 1675.851, 1627.086, 1477.928, 1904.337, 1970.514, 1958.033, 1714.306, 2089.961, 2215.401, 1770.97, 1937.336, 2256.069, 2088.461, 1371.945, 1588.166, 1825.187, 1833.408, 1591.959, 1559.9, 1860.908, 1948.155, 1945.024, 1914.496, 2110.565, 2256.448, 1883.67, 2041.186, 2354.319, 2094.562) 


data.df <-data.frame(A,B,C,D,E,F,response) 


plotting.lm <- lm(response ~ A*B*C*D*E*F*G*H, data = data.df) 
summary(plotting.lm) 

Der Code könnte straightway in R. laufen

Antwort

0

versuchen, dieses:

# save the summary 
a <- summary(plotting.lm) 

# get the coefficients, NAs should already removed. 
a$coefficients 

bearbeiten

Antwort auf Ihren Kommentar unter dieser Antwort: Sie die Funktion nutzen können coefficients zu Erhalten Sie die Koeffizienten aus dem Regressionsmodell, das von lm():

produziert wird
coefficients(plotting.lm) 
# remove the NAs 
coefficients(plotting.lm)[ !is.na(coefficients(plotting.lm))] 

die extrahierten a $ Koeffizienten ist bereits eine Matrix, wie Sie mit der Funktion überprüfen class():

coefficients2 <-a$coefficients 
class(coefficients2) 
+0

Dank Jimbou für die Beantwortung. Ich habe Ihren Code wie folgt versucht: Zusammenfassung (plotting.lm) ein <-summary (plotting.lm) coefficients2 <-a $ coefficient # finden Sie die Koeffizienten von "a $ Koeffizienten" plotting.eff <- Koeffizienten (coefficientes2) [- 1], hier kann ich die letzte Codezeile wegen der Fehlermeldung "$ operator is invalid for atomic vectors" nicht ausführen? Irgendwelche Hilfe bitte? – Amanda

+0

@Amanda hat meine Antwort aktualisiert. Hoffe es ist jetzt klar. – Jimbou

+0

Danke Jimbou. Ich habs! – Amanda

Verwandte Themen