로그 지우기() ;
/ ************************************************* ****************
이 JMP 및 R 통합 스크립트와 예제는
현장 초음파로 구성된 알래스카 파이프 라인 데이터
알래스카 파이프 라인의 결함 깊이 측정.
그런 다음 실험실에서 결함의 깊이를 다시 측정했습니다.
이러한 측정은 6 개의 서로 다른 배치로 수행되었습니다.
필드의 편향을 보정하기 위해 데이터를 분석했습니다.
실험실 측정과 관련된 측정.
이 분석에서 현장 측정은 반응 변수입니다.
실험실 측정은 예측 변수입니다.
이 데이터는 당시 연구 소장 사무실의 과학자였던 Harry Berger가 제공했습니다.
재료 연구 (현재 재료 과학 및 공학
NIST의 실험실).
이 데이터는 재료에 대해 수행 된 연구에 사용되었습니다.
미국 교통부의 교통국.
데이터 소스는 다음 링크에서 가져 왔습니다.
http://www.itl.nist.gov/div898/handbook/pmd/section6/pmd621.htm
************************************************** ************* /
R Init (); / * R에 대한 연결 시작 * /
R 제출 ( "\ [
#로드 패키지
라이브러리 (격자)
## 알래스카 파이프 라인 초음파 교정 사례 연구
## 종속 변수, 필드 결함 크기로 벡터 생성
fdef = c (18,38,15,20,18,36,20,43,45,65,43,38,33,10,50,10,50,15,53,60,18,38,15,
20,18,36,20,43,45,65,43,38,33,10,50,10,50,15,53,15,37,15,18,11,35,20,40,50, 36,
50,38,10,75,10,85,13,50,58,58,48,12,63,10,63,13,28,35,63,13,45,9,20,18,35, 20,
38,50,70,40,21,19,10,33,16,5,32,23,30,45,33,25,12,53,36,5,63,43,25,73,45, 52,
9,30,22,56,15,45)
## 독립 변수, 실험실 결함 크기로 벡터 생성
ldef = c (20.2,56.0,12.5,21.2,15.5,39.0,21.0,38.2,55.6,81.9,39.5,56.4,40.5,
14.3,81.5,13.7,81.5,20.5,56.0,80.7,20.0,56.5,12.1,19.6,15.5,38.8, 19.5,38.0,
55.0,80.0,38.5,55.8,38.8,12.5,80.4,12.7,80.9,20.5,55.0, 19.0,55.5,12.3,18.4,
11.5,38.0,18.5,38.0,55.3,38.7,54.5,38.0,12.0, 81.7,11.5,80.0,18.3,55.3,80.2,
80.7,55.8,15.0,81.0,12.0,81.4,12.5, 38.2,54.2,79.3,18.2,55.5,11.4,19.5,15.5,
37.5,19.5,37.5,55.5,80.0, 37.5,15.5,23.7,9.8,40.8,17.5,4.3,36.5,26.3,30.4,50.2,
30.1,25.5, 13.8,58.9,40.0,6.0,72.5,38.8,19.4,81.5,77.4,54.6,6.8,32.6,19.8,
58.8,12.9,49.0)
## 배치 표시기로 벡터 생성
박쥐 = c (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2, 2,2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, 3,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5, 5,5,5,5,5,5,5,5,
5,6,6,6,6,6,6,6)
## 데이터 프레임에 데이터를 저장하고 관측 횟수 결정
배치 <-as.factor (bat)
df <-data.frame (fdef, ldef, Batch)
len <-길이 (배치)
xax = "실험실 결함 크기"
yax = "필드 결함 크기"
title = "알래스카 파이프 라인 초음파 교정 데이터"
plot (ldef, fdef, xlab = xax, ylab = yax, main = title, col = "blue")
## 조건부 그림 생성
trellis.device (new = TRUE, col = FALSE)
FIG = xyplot (fdef ~ ldef | 배치,
데이터 = df,
메인 = 제목,
레이아웃 = c (3,2), col = 4,
xlab = list (xax, cex = 1.1), ylab = list (yax, cex = 1.1),
strip = function (...) strip.default (..., strip.names = c (T, T)))
무화과
## 일괄 분석
x = ldef
y = fdef
xydf = data.frame (x, y, Batch)
out = by (xydf, xydf $ Batch, function (x) lm (y ~ x, data = x))
lapply (out, summary)
#> 잔류 표준 오차 : 5 자유도에서 1.35
#> 다중 R- 제곱 : 0.9956, 조정 된 R- 제곱 : 0.9947
#> F- 통계량 : 1 및 5 DF에서 1128, p- 값 : 4.401e-07
## 일괄 회귀 결과 저장
아웃 = sapply (out, summary)
outc = sapply (out, coef)
fitse = t (outs [6,])
fitse = c (fitse [[1]], fitse [[2]], fitse [[3]], fitse [[4]], fitse [[5]], fitse [[6]])
r2 = t (출력 [8,])
r2 = c (r2 [[1]], r2 [[2]], r2 [[3]], r2 [[4]], r2 [[5]], r2 [[6]])
b0 = t (outc [1,])
b1 = t (outc [2,])
## 배치 플롯
par (mfrow = c (2,2))
id = c (1 : 길이 (b0))
xax2 = "배치 번호"
plot (id, r2, xlab = xax2, ylab = "Correlation", ylim = c (.8,1), col = "blue", pch = 16, cex = 1.25)
abline (h = 평균 (r2))
plot (id, b0 [1,], xlab = xax2, ylab = "Intercept", ylim = c (0,8), col = "blue", pch = 16, cex = 1.25)
abline (h = 평균 (b0))
plot (id, b1 [1,], xlab = xax2, ylab = "Slope", ylim = c (.5, .9), col = "blue", pch = 16, cex = 1.25)
abline (h = 평균 (b1))
plot (id, fitse, xlab = xax2, ylab = "RESSD", ylim = c (0,7), col = "blue", pch = 16, cex = 1.25)
abline (h = mean (fitse))
par (mfrow = c (1,1))
## 직선 회귀 분석
출력 = lm (fdef ~ ldef)
요약 (아웃)
## 잔여 6- 플롯
par (mfrow = c (3,2))
plot (ldef, fdef, xlab = "실험실 결함 크기",
ylab = "필드 결함 크기", main = "필드 결함 크기 대 실험실 결함 크기")
abline (reg = out)
plot (ldef, out $ residuals, ylab = "잔류", xlab = "실험실 결함 크기",
main = "잔류 vs 실험실 결함 크기")
plot (out $ fitted.values, out $ residuals, ylab = "Residuals", xlab = "예측",
main = "잔여 vs 예측")
plot (out $ residuals [2 : len], out $ residuals [1 : len-1], ylab = "잔류",
xlab = "지연 1 잔차", main = "지연 플롯")
hist (out $ residuals, ylab = "Frequency", xlab = "Residuals", main = "히스토그램")
qqnorm (out $ residuals, main = "정상 확률도")
## 중첩 회귀 함수로 원시 데이터 플롯 생성
par (mfrow = c (1,1), cex = 1.25)
plot (ldef, fdef, ylab = "필드 결함 크기", xlab = "실험실 결함 크기", col = "blue")
abline (reg = out)
title ( "Alaska Pipeline Ultrasonic Calibration Data", line = 2)
title ( "가중치없는 선 포함", line = 1)
## 잔차 대 실험실 결함 크기 플로팅
par (mfrow = c (1,1), cex = 1.25)
plot (ldef, out $ residuals, xlab = "Lab Defect Size", ylab = "Residuals",
main = "Alaska Pipeline Data Residuals-Unweighted Fit", cex = 1.25, col = "blue")
abline (h = 0)
## 반응 변수의 변환
lnfdef = log (fdef)
sqrtfdef = sqrt (fdef)
invfdef = 1 / fdef
## 변환 된 반응 변수 플로팅
par (mfrow = c (2,2))
xax = "실험실 결함 크기"
plot (ldef, fdef, xlab = xax, ylab = "필드 결함 크기", col = "blue")
plot (ldef, sqrtfdef, xlab = xax, ylab = "Sqrt (필드 결함 크기)", col = "blue")
plot (ldef, lnfdef, xlab = xax, ylab = "ln (필드 결함 크기)", col = "blue")
plot (ldef, invfdef, xlab = xax, ylab = "1 / 필드 결함 크기", col = "blue")
title (main = "응답 변수의 변환", outer = TRUE, line = -2)
## 예측 변수의 변환
lnldef = log (ldef)
sqrtldef = sqrt (ldef)
invldef = 1 / ldef
## 변환 된 예측 변수 플로팅
par (mfrow = c (2,2))
yax = "ln (필드 결함 크기)"
plot (ldef, lnfdef, xlab = "실험실 결함 크기", ylab = yax, col = "blue")
plot (sqrtldef, lnfdef, xlab = "Sqrt (실험실 결함 크기)", ylab = yax, col = "blue")
plot (lnldef, lnfdef, xlab = "ln (실험실 결함 크기)", ylab = yax, col = "blue")
plot (invldef, lnfdef, xlab = "1 / Lab Defect Size", ylab = yax, col = "blue")
title (main = "예측 변수의 변환", outer = TRUE, line = -2)
] \ ");
/ * R 데이터 프레임에서 JMP 데이터 테이블 생성 * /
Rdf = R Get (df);
Rdf << NewDataView << Set Name ( "R 데이터 프레임 테이블");
/ ** dtrdf에서 Graph Builder를 사용하여 산점도 생성 ** /
/ * 배치 열의 값 정렬 속성을 설정하여
R에서 격자 플롯을 표시하는 일치
* /
Rdf : Batch << Set Property ( "Value Ordering", Eval ({4, 5, 6, 1, 2, 3})) <<
값 레이블 (
{1 = "일괄 : 1", 2 = "일괄 : 2", 3 = "일괄 : 3", 4 = "일괄 : 4", 5 =
"일괄 : 5", 6 = "일괄 : 6"}
) <<
값 레이블 사용 (1)
;
/ ** 행 상태를 사용하여 R 플롯과 일치하도록 플롯 마커를 단색에서 공백으로 변경 *** /
Rdf << 행 상태 설정 (
[128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128]
)
;
Rdf << 그래프 빌더 (
사이즈 (457, 408),
제어판 표시 (0),
변수 (X (: ldef), Y (: fdef), Wrap (: Batch, Levels per Row (3))),
요소 (Points (X, Y, Legend (3))),
SendToReport (
급파(
{},
"그래프 제목",
TextEditBox,
{Set Text ( "Alsaka Pipeline Ultrasonic Calibration Data-JMP")}
),
Dispatch ({}, "X title", TextEditBox, {Set Text ( "Lab Defect Size")}),
급파(
{},
"Y 제목",
TextEditBox,
{텍스트 설정 ( "ln (필드 결함 크기)")}
),
디스패치 ({}, "그래프 빌더", FrameBox (1), {마커 크기 (1)}),
Dispatch ({}, "Graph Builder", FrameBox (2), {Marker Size (1)}),
디스패치 ({}, "그래프 빌더", FrameBox (3), {Marker Size (1)}),
디스패치 ({}, "그래프 빌더", FrameBox (4), {마커 크기 (1)}),
Dispatch ({}, "Graph Builder", FrameBox (5), {Marker Size (1)}),
Dispatch ({}, "Graph Builder", FrameBox (6), {Marker Size (1)})
)
);
/ * JMP 분석 플랫폼으로 플롯 및 회귀 피팅 생성 * /
/ * R에서 FIG 그래프를 가져와 JMP로 표시
* /
R 제출 ( "\ [
## 조건부 그림 생성
trellis.device (new = TRUE, col = FALSE)
FIG = xyplot (fdef ~ ldef | 배치,
데이터 = df,
메인 = 제목,
레이아웃 = c (3,2), col = 4,
xlab = list (xax, cex = 1.1), ylab = list (yax, cex = 1.1),
strip = function (...) strip.default (..., strip.names = c (T, T)))
무화과
] \ ");
picture = R Get Graphics ( "png");
New Window ( "R에서 JMP 로의 알래스카 파이프 라인 초음파 교정 데이터", picture);
Wait (10);
/ * Box-Cox 선형성 플롯 * /
R 제출 ( "\ [
## 예측 변수의 변환
lnldef = log (ldef)
sqrtldef = sqrt (ldef)
invldef = 1 / ldef
## Box-Cox 선형성 플롯
for (i in (0 : 100)) {
알파 = -2 + 4 * i / 100
if (알파! = 0) {
tx = ((ldef ** alpha)-1) / 알파
온도 = lm (lnfdef ~ tx)
임시 = 요약 (임시)
if (i == 0) {rsq = temps $ r.squared
alp = 알파}
그렇지 않으면 {rsq = rbind (rsq, temps $ r.squared)
alp = rbind (alp, alpha)}
}}
rcor = sqrt (rsq)
par (mfrow = c (1,1), cex = 1.25)
plot (alp, rcor, type = "l", xlab = "Alpha", ylab = "Correlation",
main = "Box-Cox 선형성 플롯 ln (필드) 실험실",
ylim = c (.6,1), col = "blue")
# 상관 및 알파 벡터를 BCP 데이터 프레임으로 생성
Corr <-as.vector (rcor)
알파 <-as.vector (alp)
BCP <-data.frame (Corr, Alpha)
] \ ");
RBCP = R Get (BCP);
RBCP << NewDataView << Set Name ( "알파-상관 테이블의 R 데이터 프레임");
/ * Graph Builder의 Graph Box-Cox 선형성 플롯 * /
RBCP << 그래프 빌더 (
사이즈 (421, 362),
제어판 표시 (0),
변수 (X (: Alpha), Y (: Corr)),
요소 (Smoother (X, Y, Legend (4))),
SendToReport (
급파(
{},
"그래프 제목",
TextEditBox,
{텍스트 설정 ( "Box-Cox 선형성 플롯 ln (필드)-JMP")}
),
Dispatch ({}, "Y title", TextEditBox, {Set Text ( "Correlation")})
)
);
BoxCox = R 그래픽 가져 오기 ( "png");
New Window ( "Box-Cox 선형성 플롯 ln (Field) Lab-From R", BoxCox);
Wait (10);
/ *****
Rxydf <<
그래프 빌더 (
사이즈 (533, 454),
제어판 표시 (0),
변수 (X (: x), Y (: y)),
요소 (Points (X, Y, Legend (3))),
SendToReport (
급파(
{},
"와이",
ScaleBox,
{라벨 행 (라벨 방향 ( "가로"))}
),
급파(
{},
"그래프 제목",
TextEditBox,
{Set Text ( "Alaskan Pipeline Ultrasonic Calibration Data-JMP")}
),
Dispatch ({}, "X title", TextEditBox, {Set Text ( "Lab Defect Size")}),
급파(
{},
"Y 제목",
TextEditBox,
{텍스트 회전 ( "왼쪽"), 텍스트 설정 ( "필드 결함 크기")}
)
)
);
*** /
/ ** 데이터에 맞는 첫 번째 초기 회귀 직선 모델 수행
Rxydf << 이변 량 (
Y (: y),
X (: x),
맞춤 선 ({선 색상 ({57, 177, 67})}),
SendToReport (
Dispatch ({ "Linear Fit"}, "Lack Of Fit", OutlineBox, {Close (0)})
)
);
** /
R 용어 (); / * R에 대한 연결 종료 * /