File:MATLABNPChart.png
From Wikimedia Commons, the free media repository
Jump to navigation
Jump to search
MATLABNPChart.png (561 × 420 pixels, file size: 4 KB, MIME type: image/png)
File information
Structured data
Captions
Captions
Add a one-line explanation of what this file represents
Summary
[edit]DescriptionMATLABNPChart.png |
English: A en:MATLAB-generated en:np-chart for a process that experienced a 1.5σ drift starting at midnight. |
Date | |
Source | Own work |
Author | DanielPenfield |
Licensing
[edit]I, the copyright holder of this work, hereby publish it under the following license:
![w:en:Creative Commons](https://upload.wikimedia.org/wikipedia/commons/thumb/7/79/CC_some_rights_reserved.svg/90px-CC_some_rights_reserved.svg.png)
![attribution](https://upload.wikimedia.org/wikipedia/commons/thumb/1/11/Cc-by_new_white.svg/24px-Cc-by_new_white.svg.png)
![share alike](https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Cc-sa_white.svg/24px-Cc-sa_white.svg.png)
This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license.
- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
Source code
[edit]#!/usr/bin/perl -w
#
# randomly generate process observations that simulate a
# binomially-distributed process in the state of statistical control
# (p_setup.csv) and simulate the same process experiencing a drift of
# magnitude $drift starting two hours into the $shift shift
# (p_monitoring.csv)
#
use strict;
use Math::Random;
my %shiftSchedule = (
"first" => { "start" => 6.00, "end" => 14.00 },
"second" => { "start" => 14.00, "end" => 22.00 },
"third" => { "start" => 22.00, "end" => 6.00 }
);
my $shift = "third"; # shift to monitor
my $inspectionRate = 1 / 2; # every 1/2 hour
my $drift = 1.5; # sigma drift to simulate
my $m = 25; # samples in control chart setup
my $target = 0.10; # fraction nonconforming target
my $p = $target;
my $n = # observations per sample
int((9 * $p * (1 - $p)) / ($drift * $p * $drift * $p) + 0.5);
my $hour;
my $i;
my $minute;
my $observation;
my $setupM = $m;
print "n = $n\n";
#
# simulate control chart setup
#
open(SETUPCSV, ">p_setup.csv") || die "! can't open \"p_setup.csv\" ($!)\n";
for ($i = 1; $i <= $m; $i++) {
$observation = Math::Random::random_binomial(1, $n, $p);
print SETUPCSV $observation . "\r\n";
}
close(SETUPCSV);
#
# simulate control chart monitoring
#
open(MONITORINGCSV, ">p_monitoring.csv") || die "! can't open \"p_monitoring.csv\" ($!)\n";
$m = $shiftSchedule{$shift}{"end"} - $shiftSchedule{$shift}{"start"};
if ($m < 0) {
$m += 24;
}
$m /= $inspectionRate;
for ($i = 1; $i <= $m; $i++) {
$hour = int($i * $inspectionRate + $shiftSchedule{$shift}{"start"});
if ($hour >= 24) {
$hour -= 24;
}
$minute = ($i & 0x1) ? (60 * $inspectionRate) : 0;
if ($i >= (0.25 * $m)) {
if ($i < (0.75 * $m)) {
$p = $target + ($drift * $target / (0.5 * $m)) * ($i - (0.25 * $m));
} else {
$p = $target + $drift * $target;
}
}
$observation = Math::Random::random_binomial(1, $n, $p);
printf MONITORINGCSV "'%d:%02d',%d\r\n", $hour, $minute, $observation;
}
close(MONITORINGCSV);
%
% display an np-chart control chart in MATLAB
%
clear
%
% rational subgroup size
%
n = 36
%
% Phase I
%
% compute the control chart center line and control limits based on a
% process that is simulated to be in a state of statistical control
%
% note that MATLAB requires full counts for both p- and np-charts (as
% opposed to requiring the user to precalculate the average number of
% nonconformities per rational subgroup)
%
%
setupobservations = csvread('p_setup.csv');
setupstats = controlchart(setupobservations, 'charttype', 'np', 'unit', n);
%
% Phase II
%
% read in the process observations representing the monitoring phase
%
observations = importdata('p_monitoring.csv');
%
% first column is the time of the observation (24 hour clock)
%
halfhourlylabel = observations.rowheaders;
%
% second column consists of the observations (counts of
% nonconformances per rational subgroup)
%
monitoringobservations = observations.data;
%
% just display labels on the "on the hour" ticks
%
emptylabel = cell(size(monitoringobservations,1) - size(halfhourlylabel,1), 1);
emptylabel(:) = {''};
hourlylabel = vertcat(halfhourlylabel(2:2:end), emptylabel);
%
% plot the control chart for the monitoring phase observations based
% on the "in control" estimates for the process mean
%
monitoringstats = controlchart(monitoringobservations, ...
'charttype', 'np', ...
'label', halfhourlylabel, ...
'unit', n, ...
'mean', setupstats.p, ...
'sigma', setupstats.p);
title('np chart for quality characteristic XXX')
xlabel('Sample')
ylabel('Number nonconforming')
%
% the labels supplied to controlchart() only appear when the user
% selects a plotted point with her mouse--we have to explicitly
% set labels in the X axis if we want them
%
set(gca,'XTickLabel', hourlylabel)
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 14:05, 22 June 2013 | ![]() | 561 × 420 (4 KB) | DanielPenfield (talk | contribs) | User created page with UploadWizard |
You cannot overwrite this file.
File usage on Commons
There are no pages that use this file.
Metadata
This file contains additional information such as Exif metadata which may have been added by the digital camera, scanner, or software program used to create or digitize it. If the file has been modified from its original state, some details such as the timestamp may not fully reflect those of the original file. The timestamp is only as accurate as the clock in the camera, and it may be completely wrong.
Author | |
---|---|
Copyright holder |
|
Image title |
|
Horizontal resolution | 37.8 dpc |
Vertical resolution | 37.8 dpc |
Date and time of digitizing |
|
Software used |